Results 1 to 3 of 3

Thread: [Resolved] How to response to client and open a form when DataArrival?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    19

    Resolved [Resolved] How to response to client and open a form when DataArrival?

    Hello

    I have a server side program, it receive client message with WinSock. After receiving data, it will process the content and return a result message to client. If process result is successful (0), server side will open a form to keep process the next step, and close itselft at the same time. The problem is: When I open the form, sendData will not process until the new form was closed. I tried to run unload current form only, it will turn to unload but still cannot send response. It seems that SendData in DataArrival will process until DataArrival Complete. How to fix this problem? Thanks a lot and sorry for my poor English. Here is the related code:

    Code:
    Private Sub sckPDA_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    
       Dim sStatus As String
        'Process received data
        sckPDA(Index).GetData sStatus, vbString
        If VerifyStatus(sStatus) Then
            resmsg = "0"
            blnStatusCorrect = True
        Else
            resmsg = "-1"
            blnStatusCorrect = False
        End If
        
         'A feedback to client side  
        If sendResponse(resmsg) = True Then
            sckSend.Close
            'Open form to process next step
            frmPhase2.Show vbModal, Me
        End If
            
        Unload Me
    End Sub
    
    Private Function sendResponse(ByVal resmsg As String) As Boolean
        sckSend.Close
        sckSend.Connect
        sendResponse = False
        
        Do
        DoEvents
            If sckSend.State = sckConnected Then
                sckSend.SendData resmsg
                sendResponse = True
            End If
        Loop Until sckSend.State = 7
        
    End Function
    Last edited by SKAWilliam; Dec 20th, 2007 at 03:39 AM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to response to client and open a form when DataArrival?

    I suspect that you're closing the socket before the Send has completed. You should, perhaps, be using the SendComplete event to signal when the data has been sent and only when you receive that signal, close the socket.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    19

    Re: How to response to client and open a form when DataArrival?

    Problem solved, thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width