Click to See Complete Forum and Search --> : WinSock GetData method...
ROAMER
Dec 7th, 2005, 01:20 PM
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 :wave:
opus
Dec 7th, 2005, 03:06 PM
the data sent via winsock is coming in so fast, that the two messages are put together.
Do something like that
text1.text = "hi"
socket.senddata "Text1:"& text1.text & ";"
text2.text = "vb"
socket.senddata "Text2:"& text2.text & ";"
and on the recieving end
socket1(index).getdata strData
Read_Message strData
Public Sub Read_Message(strData as String)
Dim msgtype as String
Dim msg as String
'Identify the MessageType (Text1 or Text2)
msgtype = Left(strData, InStr(1, strData, ":") - 1)
'Seperate the Data part from the Identifier
msg = Mid(strData, InStr(1, strData, ":") + 1)
If msgtype = "Text1" Then
text1.text = CSng(Left(msg, InStr(1, msg, ";") - 1))
End if
If msgtype = "Text2" Then
text2.text = CSng(Left(msg, InStr(1, msg, ";") - 1))
End if
'cut off the processed part
msg = Mid(msg, InStr(1, msg, ";") + 1)
'If the recieved two mesages at once, the Read_message will be called again
If Len(msg) > InStr(1, msg, ";") Then
Stream = Mid(msg, InStr(1, msg, ";") + 1)
Read_Message msg
End If
End Sub
Doobs
Dec 14th, 2005, 07:44 AM
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.
Jmacp
Dec 14th, 2005, 08:45 AM
You always put a doevents after a senddata,
This will do the trick,
text1.text = "hi"
socket.senddata "Text1:"& text1.text & ";"
Doevents
text2.text = "vb"
socket.senddata "Text2:"& text2.text & ";"
Doevents
opus
Dec 15th, 2005, 04:51 AM
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.
|2eM!x
Dec 15th, 2005, 08:12 PM
Opus, why not end with a vbcrlf or a chr(0) so you know that the packet is finished?
opus
Dec 19th, 2005, 01:13 PM
|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!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.