Valhalla Legends Forums Archive | Visual Basic Programming | Hanging on Connection (Winsock)

AuthorMessageTime
DaRk-FeAnOr
When I am connecting to battle.net, it seems like the packets are queued and dataarrival is not called. Sometimes it connects all the way. Sometimes it does not. Once I send a chat packet to battle.net (during the hanging) my client reads the next packet, although I am then IPbanned for sending chat during the connection sequence. Here is an example of what would happen.
[quote]
BNET: Connecting....
BNET: Connected
(hangs)
<username> randomtext!
BNET: 0x51 Recieved
[/quote]
I have no idea what is causing this and why dataarrival does not seem to be called.
December 25, 2003, 7:05 AM
Grok
You've given us nothing to go by in assisting you. But I suspect your winsock control usage is not solid. Show me your DataArrival? Are you buffering the data to a queue, then processing it separately?
December 25, 2003, 7:36 AM
DaRk-FeAnOr
My data arrival sub looks something like this:

[code]
Private Sub sckbnet_DataArrival(ByVal bytesTotal As Long)
Static strBuffer As String
Dim strTemp As String, lngLen As Long
strBuffer = strBuffer & strTemp
While Len(strBuffer) > 4
lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
If Len(strBuffer) < lngLen Then Exit Sub
Bnet.parseBNET (Left(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
strBuffer = Mid(strBuffer, lngLen + 1)
Wend
end sub
[/code]
iform is the index of the form sending the parse request.
December 25, 2003, 8:04 AM
Grok
Obviously you don't really want help.

Post your real DataArrival, unmodified, or don't post at all.
December 25, 2003, 11:05 AM
CupHead
One of the more crucial parts you are missing, edited out or not, is [code]sckbnet.GetData strTemp[/code]

Other than that, I'll have to agree with what Grok said.
December 25, 2003, 2:31 PM
TheMinistered
I would assume that he did not edit out the call to GetData. Why would I say this? Simple, what we he have to loose by posting a call to GetData? It simply reveals no secrets whatsoever. I am a mindreader! woohoo!

So, my suggestion is you add the call to GetData to your code... it helps a bunch!
December 25, 2003, 3:52 PM
DaRk-FeAnOr
I edited out some stuff, because it has to do with proxy connection and the problem is not in the proxy code at all, but whatever here is the entire thing:
[code]
Private Sub sckbnet_DataArrival(ByVal bytesTotal As Long)
Static strBuffer As String
Dim strTemp As String, lngLen As Long
sckbnet.GetData strTemp, vbString
If proxyuse = True Then
If sock5use = False Then
If connected = False Then
Select Case Mid(strTemp, 1, 2)
Case Chr(0) & Chr(&H5A)
connected = True
addchat3 iform, vbGreen, "SOCK4: Request Granted"
AddChat2 vbGreen, "SOCK4: Request Granted"
sckbnet.SendData Chr(1)
BNLS.p0x50 iform, product
Exit Sub
Case Chr(0) & Chr(&H5B)
addchat3 iform, vbRed, "SOCK4: Request Rejected Or Failed"
AddChat2 vbRed, "SOCK4: Request Rejected Or Failed"
BNLS.recon (iform)
Exit Sub
Case Chr(0) & Chr(&H5C)
addchat3 iform, vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
AddChat2 vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
Call BNLS.recon(iform)
Exit Sub
Case Chr(0) & Chr(&H5D)
addchat2 vbRed, "SOCK4: Request Rejected Because the Client Program and the ID Report Different User-IDs"
AddChat2 vbRed, "SOCK4: Request Rejected Because SOCKS server cannot IDENT on the client"
Call BNLS.recon(iform)
Exit Sub
Case Else
addchat3 iform, vbYellow, "SOCK: Proxy Detected as SOCK5, Switching Connection Sequence"
sckbnet.Close
Call sock5
Exit Sub
End Select
End If
Else
Select Case Mid(strTemp, 1, 5)
Case Chr(0) & Chr(&H5)
Dim splt() As String, str As String, i As Integer
server = LCase(server)
splt = Split(server, ".")
For i = 0 To UBound(splt)
str = str & Chr(CStr(splt(i)))
Next i
sckbnet.SendData Chr(5) & Chr(1) & Chr(0) & Chr(1) & str & Chr(&H17) & Chr(&HE0)
Exit Sub
Case Chr(5) & Chr(0) & Chr(0) & Chr(1) & Chr(&HC8)
addchat3 iform, vbGreen, "SOCK5: Request Granted"
AddChat2 vbGreen, "SOCK5: Request Granted"
sckbnet.SendData Chr(1)
BNLS.p0x50 iform, product
Exit Sub
End Select
End If
strBuffer = strBuffer & strTemp
While Len(strBuffer) > 4
lngLen = Val("&H" & StrToHex(StrReverse(Mid$(strBuffer, 3, 2))))
If Len(strBuffer) < lngLen Then Exit Sub
bnet.parseBNET (Left$(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
strBuffer = Mid$(strBuffer, lngLen + 1)
Wend
Else
strBuffer = strBuffer & strTemp
While Len(strBuffer) > 4
lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
If Len(strBuffer) < lngLen Then Exit Sub
bnet.parseBNET (Left(strBuffer, lngLen)), iform, product, cdkey, user, pass, server
strBuffer = Mid(strBuffer, lngLen + 1)
Wend
End If
End Sub
[/code]
I have been running through my code a few times with the debugger, and I think that it is just not called at all. I will try what theministered said and call this function somewhere in the code where it is hanging and see what happens.
December 25, 2003, 4:15 PM
Grok
Trying to step through this in a debugger will continue to mess with your mind. Add a logging function, use the ubiquous DebugOutput, or something else, to create a dump log. Don't try to interfere with Visual Basic receiving data or you'll miss DataArrival events. When you miss those (because you're already in DataArrival), they don't happen again. Therefore, you get out of sync with the server.

Try troubleshooting your connection in runtime by examining logs of SND/RCV. Much easier.
December 25, 2003, 4:43 PM
Grok
First problem I saw was your indenting. Fix the indenting.

From a code manageability viewpoint, I noticed in your DataArrival you are including business logic and transmitting more data. Both of those should have their own routines. You can't be receiving data while simultaneously figuring out what to do with it, and sending out more data. You can, but it gets hard to manage.

Rearrange it so DataArrival does nothing but buffer the data received. It's not necessary for you to respond to it so suddenly.

Rearrange your sending so there's only one function that can send data over the winsock control. That function will only do one thing, and that's send the data in the packet buffer. The send function would be using the proxyuse, socks5use, and connected booleans to decide how to transmit, exactly.

Once you've separated the network from the transport, and that from the presentation and application, it gets pretty easy to see what's going on.
December 25, 2003, 4:56 PM
Spht
[quote author=DaRk-FeAnOr link=board=31;threadid=4441;start=0#msg37058 date=1072339445]
[code]
While Len(strBuffer) > 4
[/code]
[/quote]

It seems here that if Battle.net sends you a packet with no content (just 4 bytes which is the header), the message will be put into your buffer and unprocessed until another message is received.
December 26, 2003, 2:41 AM
DaRk-FeAnOr
I have tried a lot of different things and the best idea that I have is that battle.net might not be sending the packet back to me, but queueing it server side. This hanging only happense on packet 0x51 (and sometimes 0x3A) when I send multiple 0x51 packets within a short time period. What I did is that i make sure that every 0x51 / 0x3A that is sent is 150 ms apart from the last, and it all works. Hurray :) Thanks for all the help.
December 26, 2003, 3:20 AM
Grok
I don't agree. Blizzard isn't picking on you in particular in how it responds, so any problem is in your implementation.
December 26, 2003, 4:03 AM

Search