Results 1 to 7 of 7

Thread: WinSock GetData method...

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    13

    WinSock GetData method...

    i m using Winsock control in my client server application using Visual Basic6.
    i m sending more than one data fields from the client machine to the server.
    e.g i've two text boxes i send the values of the two text boxes to the server but on the server machine, i've a code for DataArrival which gives me the combined data(values of both text boxes at once) following is the code from client
    text1.text = 'hi'
    socket.senddata text1.text vbString
    text2.text = 'vb'
    socket.senddata text2.text vbString
    following is the code from server
    socket1(index).getdata strData vbString
    it shows me the combined value of the both text boxes at onec like "hi vb"
    i want these two values seperatly.
    it's urgent, anyone knows about it. resolve this for me

    ROAMER
    Last edited by ROAMER; Dec 8th, 2005 at 03:26 AM. Reason: Solved

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: WinSock GetData method...

    the data sent via winsock is coming in so fast, that the two messages are put together.
    Do something like that
    VB Code:
    1. text1.text = "hi"
    2. socket.senddata "Text1:"& text1.text & ";"
    3. text2.text = "vb"
    4. socket.senddata "Text2:"& text2.text & ";"
    and on the recieving end
    VB Code:
    1. socket1(index).getdata strData
    2. Read_Message strData
    3.  
    4. Public Sub Read_Message(strData as String)
    5. Dim msgtype as String
    6. Dim msg as String
    7. 'Identify the MessageType (Text1 or Text2)
    8. msgtype = Left(strData, InStr(1, strData, ":") - 1)
    9. 'Seperate the Data part from the Identifier
    10. msg = Mid(strData, InStr(1, strData, ":") + 1)
    11. If msgtype = "Text1" Then
    12.        text1.text = CSng(Left(msg, InStr(1, msg, ";") - 1))
    13. End if
    14. If msgtype = "Text2" Then
    15.        text2.text = CSng(Left(msg, InStr(1, msg, ";") - 1))
    16. End if
    17. 'cut off the processed part
    18. msg = Mid(msg, InStr(1, msg, ";") + 1)
    19. 'If the recieved two mesages at once, the Read_message will be called again
    20. If Len(msg) > InStr(1, msg, ";") Then
    21.     Stream = Mid(msg, InStr(1, msg, ";") + 1)
    22.     Read_Message msg
    23. End If
    24. End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    New Member
    Join Date
    Sep 2005
    Posts
    14

    Post Re: WinSock GetData method...

    Dude, thats way to complicated for this simple task.

    Also, dont send to packets, just one.

    Dim Length as Byte
    Dim VariableOne as string, VariableTwo as string
    Length = Format(Len(VariableOne) + Len(VariableTwo) + 3, "00#")
    Winsock1.senddata Length & VariableOne & "~" & VariableTwo

    On the Receiver

    Dim Temp as string
    Dim Length as byte
    Dim VariableOne as string, VariableTwo as string, TempStr as string
    Winsock1.Getdata Temp
    Length = Mid(Temp, 1, 3)
    If Length = Len(Temp) then
    For I = 4 To Len(Temp)
    TempStr = Mid(Temp, I, 1)
    If TempStr <> "~" then
    If Delimiter <> True then
    VariableOne = VariableOne & TempStr
    Else
    VariableTwo = VariableTwo & TempStr
    End If
    Else
    Delimiter = True
    End if
    Else
    'Wrong Length, Maybe put code here to ask for a resend
    End If
    Next I

    This should work, Its not tested but thats the base any errors should be easly removed.

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: WinSock GetData method...

    You always put a doevents after a senddata,

    This will do the trick,

    VB Code:
    1. text1.text = "hi"
    2.     socket.senddata "Text1:"& text1.text & ";"
    3.  
    4.     Doevents
    5.  
    6.     text2.text = "vb"
    7.     socket.senddata "Text2:"& text2.text & ";"
    8.  
    9.     Doevents

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: WinSock GetData method...

    Jmcap, the DoEvents will help to seperate the two messages, but if nothing else is going on, the two messagfes could still be recieved as one. To cover that the "Read_Message" Sub is used.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: WinSock GetData method...

    Opus, why not end with a vbcrlf or a chr(0) so you know that the packet is finished?

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: WinSock GetData method...

    |2eM!x no problem with your suggestion [if you look at my suggestion, I'M using a ";"], I think you definetly need a sign that is "telling" the end of the message.
    But whatever you use, your routine to read those messages should be able to seperate a "message" which consists of more than one message!
    And doing this "reading" a unique characters is coming in real handy!

    And to Roamer (the one who started that thread), you need the edit the first post and either ADD "SOLVED " to the TITLE or use the CHECKMARK. It doesn't help to put Solved in the Raeson for Editing!
    Last edited by opus; Dec 19th, 2005 at 02:17 PM.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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