|
-
Nov 19th, 2007, 03:10 AM
#1
Thread Starter
Frenzied Member
What is the best way of telling when a message starts/ends with winsock?
Currently im doing this..
vb Code:
sckAccept(index).GetData data
data = addendum & data
lines = FindBetween2(data, "<My_Start_String>", "<My_End_String>")
For x = 0 To UBound(lines) - 1
data = Replace$(data, "<My_Start_String>" & lines(x) & "<My_End_String>", "")
debug.print "MESSAGE RECEIVED: " & lines(x)
next
addendum = data
But surely there is a better way out there.. (ps: findbetween2 returns the string data between 2 strings.. in case of multiple matches it returns an array)
-
Nov 19th, 2007, 03:52 AM
#2
Thread Starter
Frenzied Member
Re: What is the best way of telling when a message starts/ends with winsock?
How does this look? Can it be made faster?
vb Code:
Dim endPoint As Long
Const endString As String = "<My_End_String>"
Winsock.GetData Data
Data = addendum & Data
Do
endPoint = InStr(Data, endString)
If endPoint > 0 Then
Debug.Print "message: " & Left(Data, endPoint - 1)
Data = Right(Data, Len(Data) - endPoint - Len(endString) + 1)
Else
Exit Do
End If
Loop
addendum = Data
-
Nov 19th, 2007, 04:36 AM
#3
Re: What is the best way of telling when a message starts/ends with winsock?
The best way is to not use a string but one byte to start and one byte to end (STX and ETX). These are standard string communications protocols that you should look into.
-
Nov 19th, 2007, 01:18 PM
#4
Thread Starter
Frenzied Member
Re: What is the best way of telling when a message starts/ends with winsock?
 Originally Posted by randem
The best way is to not use a string but one byte to start and one byte to end (STX and ETX). These are standard string communications protocols that you should look into.
this would be tough when sending binary data..
-
Nov 19th, 2007, 02:26 PM
#5
Re: What is the best way of telling when a message starts/ends with winsock?
Just send a header data where you specify the data length, see this thread for an example:
http://www.vbforums.com/showthread.php?t=377648
-
Nov 19th, 2007, 10:09 PM
#6
Re: What is the best way of telling when a message starts/ends with winsock?
Yes, it would be tough but you stated you are sending string data not binary data...
-
Nov 20th, 2007, 01:55 AM
#7
Thread Starter
Frenzied Member
Re: What is the best way of telling when a message starts/ends with winsock?
yes but theres crazy characters in the string
-
Nov 20th, 2007, 02:08 AM
#8
Re: What is the best way of telling when a message starts/ends with winsock?
Then it's not a string, it's binary data...
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
|