Very poor TCP GET performance

Blitz3D Forums/Blitz3D Programming/Very poor TCP GET performance

Imphenzia(Posted 2010) [#1]
I've just noticed that I have a problem (verified on two computers) with OpenTCPStream and getting text via HTTP.

I'm just implementing a simple status check that reads from a web page and it's taking 10+ seconds and then terminates with an error (no EOL(tcp)).

Can anyone test this code and report the outcome please?

; try the URL (http://www.beatball2.com/scorestatus/ in a browser and compare the speed to this code

timer = MilliSecs()
Print "Connecting..."
tcp=OpenTCPStream( "www.beatball2.com",80 )

If Not tcp Print "Failed.":WaitKey:End

Print "Connected! Sending request..."

WriteLine tcp,"GET /scorestatus/ HTTP/1.1"
WriteLine tcp,"Host: www.beatball2.com"
WriteLine tcp,Chr$(10)

If Eof(tcp) Print "Failed.":WaitKey:End

Print "Request sent! Waiting for reply..."
While Not Eof(tcp)
Print ReadLine$( tcp )
Wend

If Eof(tcp)=1 Then Print "Success!" Else Print "Error!"

CloseTCPStream tcp

Print "Time: " + ((MilliSecs() - timer)/1000) + "sec"

WaitKey
End


On my machine it displays "HTTP/1.1 200 OK" fast, then a 10 second delay before the remaining text appears

I've also used wireshark to capture the network traffic and the packet that contains the "HTTP/1.1 200 OK" response also contains all the other information on that little page, but Blitz3D seems to hang when processing it. I'm using Blitz3D 1.106


Also if you have any ideas of how it could be fixed I'd appreciate any suggestions.

Last edited 2010


_Skully(Posted 2010) [#2]
TCP packets are reliable which means it waits for response, this is why most games use UDP with a reliability routine to resend lost packets (when required)


Imphenzia(Posted 2010) [#3]
Yep - UDP is a given for gaming but when it comes to HTTP traffic it isn't possible. This is simple status check for online scores so it reads the status from a web page.

This particular bug has nothing to do with whether it is UDP or TCP though. As I mentioned when I capture the TCP packet with Wireshark the computer has received all data right a way but Blitz3D itself hangs even though it has received the full packet.

I try the same type of request in BlitzMax and I get instant response every time < 1 sec. Blitz3D hangs for 10 seconds (on my two computers).


RifRaf(Posted 2010) [#4]
Perhaps its your host.. have your tried storing the file on a different host to test this out ? Tiny Tanks somtimes takes up to 10 seconds to verify versions and get server listings from the database if my host is having latency issues , wich happens from time to time.


Yan(Posted 2010) [#5]
WriteLine tcp, "GET /scorestatus/ HTTP/1.1"
WriteLine tcp, "Host: www.beatball2.com"
WriteLine tcp, "Connection: close"
WriteLine tcp, Chr$(10)


Last edited by your momma

Last edited 2010


Imphenzia(Posted 2010) [#6]
@Yan - thank you thank you thank you =)

That "Connection: close" does the trick :P

Thanks to your others for your suggestions too - this was driving me around the bend :)