|
-
Dec 7th, 2005, 02:20 PM
#1
Thread Starter
New Member
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
-
Dec 7th, 2005, 04:06 PM
#2
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:
text1.text = "hi"
socket.senddata "Text1:"& text1.text & ";"
text2.text = "vb"
socket.senddata "Text2:"& text2.text & ";"
and on the recieving end
VB Code:
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
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!
-
Dec 14th, 2005, 08:44 AM
#3
New Member
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.
-
Dec 14th, 2005, 09:45 AM
#4
Re: WinSock GetData method...
You always put a doevents after a senddata,
This will do the trick,
VB Code:
text1.text = "hi"
socket.senddata "Text1:"& text1.text & ";"
Doevents
text2.text = "vb"
socket.senddata "Text2:"& text2.text & ";"
Doevents
-
Dec 15th, 2005, 05:51 AM
#5
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!
-
Dec 15th, 2005, 09:12 PM
#6
Re: WinSock GetData method...
Opus, why not end with a vbcrlf or a chr(0) so you know that the packet is finished?
-
Dec 19th, 2005, 02:13 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|