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)
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
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.
Re: What is the best way of telling when a message starts/ends with winsock?
Quote:
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..
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
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...
Re: What is the best way of telling when a message starts/ends with winsock?
yes but theres crazy characters in the string :D
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...