Author | Message | Time |
---|---|---|
BaDDBLooD | This is darn wierd! I am using the Winsock API Socket class, i'm sure some of you have used this. It includes mSocketSupprt, and cSocket. My problem is in the BNET Data Arrival. i have a Parse sub, and whenever i try and parse the packet's i get a error. For example: [code] Public Sub ParseBNCS(ByVal Data As String) Dim PacketID As Byte PacketID = Asc(Mid(Data, 2, 1)) Select Case PacketID Case &H0 MsgBox "0x00" Case &H25 MsgBox "0x25" Case &H50 MsgBox "0x50" End Select End Sub [/code] This code works, however this code gives me the error: Run-time error '5': Invalid Procedure call or argument [code] Public Sub ParseBNCS(ByVal Data As String) Dim PacketID As Byte PacketID = Asc(Mid(Data, 2, 1)) Select Case PacketID Case &H0 With Buffer .SendPacket frmMain.sckBNCS, BNCS, &H0 End With Case &H25 With Buffer .InsertNonNTString Mid(Data, 5, 4) .SendPacket frmMain.sckBNCS, BNCS, &H25 End With Case &H50 Dim ExeHash As String, MpqName As String ServerToken = Val("&h" & StrToHex(StrReverse(Mid(Data, 9, 4)))) ExeHash = Mid(Data, 38, Len(Data) - 2) MpqName = Mid(Data, 25, 12) MpqName = Val(Mid(MpqName, 8, 1)) AddText frmMain.rtbChat, vbYellow, ExeHash AddText frmMain.rtbChat, vbYellow, MpqName With Buffer .InsertDWORD GetBNLSByte() .InsertDWORD CLng(MpqName) .InsertNTString ExeHash .SendPacket frmMain.sckBNLS, BNLS, &H9 End With End Select End Sub [/code] Data Arrival as requested by Chronic [code] Private Sub sckBNCS_OnDataArrival(ByVal bytesTotal As Long) Static Buffer As String, Data As String, Length As Long sckBNCS.GetData Data, vbString Buffer = Buffer & Data While Len(Buffer) > 4 Length = Val("&H" & StrToHex(StrReverse(Mid(Buffer, 3, 2)))) If Len(Buffer) < Length Then: Exit Sub ParseBNCS (Left(Buffer, Length)) Buffer = Mid(Buffer, Length + 1) Wend End Sub [/code] When i debug the Environment the string "Data" is Empty. When i debug the Data Arrival, and step through the parse sub i don't get any error at all. Any Help will be Apreciated. | August 24, 2004, 2:52 AM |
K | Well that makes sense. [code] PacketID = Asc(Mid(Data, 2, 1)) [/code] If Data is empty, how can you access the second character in it? You need to only call your Parse function when you receive a complete packet. | August 24, 2004, 3:23 AM |
BaDDBLooD | Yes i know i can't do that. If you read my statement at the top it WORKS when i just have a Message box, whenever i implement any real code it doesn't work! EDIT: i uploaded the source code to my webhost if anyone wanted a more in depth look at the problem. | August 24, 2004, 3:26 AM |
Kp | [quote author=BaDDBLooD link=board=17;threadid=8346;start=0#msg77106 date=1093317975]Yes i know i can't do that. If you read my statement at the top it WORKS when i just have a Message box, whenever i implement any real code it doesn't work![/quote] Probably because the extra delay imposed by the message box allows the other messages to be fully delivered, so you receive them fine. Perhaps you should try following K's suggestion, and only parse complete messages. | August 24, 2004, 4:16 AM |
BaDDBLooD | I don't know how to fix this so imma screw it. Thanks for everyone's help, it's much apreciated. EDIT: Ok Nevermind, i did fix it. my String To Hex Function was totally screwed over. Along with a few other small problems. The problem was ( After i debugged a whole lot ) i recieve 0x25, 0x50, than the broken str to hex function gave me a whole assload of nothing. Thanks again to everyone for there help. | August 24, 2004, 5:16 AM |