Alright, well I'm making a filter gateway for battle.net clients, so that instead of client->server connection it goes client->gateway->server... and it's giving me a problem of the client receiving the data sent by my program multiple times:
(http://www.l2uthlessnet.com/ss2.png)
My code for receiving Battle.net data:
Private Sub wsBNET_DataArrival(ByVal bytesTotal As Long)
Static Buffer As String
Dim Data As String, Length As Long
Call wsBNET.GetData(Data, vbString, bytesTotal)
Buffer = Buffer & Data
While Len(Buffer) >= 4
Length = GetWORD(Mid$(Buffer, 3, 2))
If Length > Len(Buffer) Then Exit Sub
Call ParseRecvData(Buffer)
Buffer = Mid$(Buffer, Length + 1)
Wend
End Sub
Code for ParseRecvData():
Public Sub ParseRecvData(ByVal Data As String)
Select Case Asc(Mid$(Data, 2, 1))
Case &HA:
Con.Username = TrimString(Mid$(Data, 5))
Case &H50:
Con.ServerToken = GetDWORD(Mid$(Data, 9, 4))
Con.MPQNumber = CInt(Mid$(Data, 32, 1))
Con.HashValue = TrimString(Mid$(Data, 38))
End Select
Call frmMain.wsListen.SendData(Data)
End Sub
Any ideas? I tried using DoEvents and checking if the Data was already sent by the socket but it still happens... any input is appreciated. Thanks.
Ah, i had this problem a few times, i think it was because of the static string.
(I take it this only happens now and then?)
try:
Private Sub wsBNET_DataArrival(ByVal bytesTotal As Long)
Static Buffer As String
Dim Data As String, Length As Long
Call wsBNET.GetData(Data, vbString, bytesTotal)
Buffer = Buffer & Data
While Len(Buffer) >= 4
Length = GetWORD(Mid$(Buffer, 3, 2))
If Length > Len(Buffer) Then Exit Sub
Data = left(Buffer, lengh)
Call ParseRecvData(Data)
buffer = mid(buffer, 1 + lengh)
Wend
End Sub
Hope this helps
omg Ringo you rock. thanks much.. although I still don't understand why it happens in the first place.. I guess another gay VB thing.