Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'"MSG|" & txtNameBox.Text & "|" & txtChatBox.Text & Chr$(0)
Dim strData As String, lonPos As Long
Dim strCommand As String, strBuff() As String
Dim lonLoop As Long, strSegments() As String
'Get entire data.
Winsock1.GetData strData
'Search for the end of packet delimiter (Chr$(0))
lonPos = InStr(1, strData, Chr$(0))
If lonPos > 0 Then
'End of packet found. Loop through all packets.
strBuff() = Split(strData, Chr$(0))
For lonLoop = 0 To UBound(strBuff())
If Len(strBuff(lonLoop)) > 0 Then
'Split the data into segments.
'MSG|NameBox|ChatBox becomes
'(0) - MSG
'(1) - NameBox
'(2) - ChatBox
strSegments() = Split(strBuff(lonLoop), "|")
'Check the command (packet header).
Select Case strSegments(0)
Case "MSG"
'This data is a chat message.
textchat.Text = strSegments(1) & ": " & strSegments(2)
Case "..."
'Another command here.
End Select
End If
Next lonLoop
Else
If InStr(1, strData, "|") > 0 Then
strSegments = Split(strData, "|")
'Same select case statement as in the loop.
'Check the command (packet header).
Select Case strSegments(0)
Case "MSG"
'This data is a chat message.
textchat.Text = strSegments(1) & ": " & strSegments(2)
Case "..."
'Another command here.
End Select
End If
End Sub