The problem is the web server , apache web server have a default keep alive of 5 seconds , so the web servers will close your connection after 5 sec. sure you can adjust this on the server but all web servers will have a low keep alive ( to free up connections ). You can avoid this if you keep sending data to the webserver.
Try this sample;
// Project: mp peek server test.
// Created: 2015-11-19
// set window properties
SetWindowTitle( "mp peek test" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
stat = 0
http = CreateHTTPConnection()
SetHTTPTimeout( http, 6000 )
SetHTTPHost( http, "www.playgames2.com", 0 )
SendHTTPRequestASync( http, "agk2.php" , "f=1&c=Ready" )
// main loop
responcetimeavg# = 0
rstart# = timer()
rend# = 0
lastres# = 0
gotmessages# = 1
servererror# = 0
mytimer# = timer()
do
if getrawkeypressed(27) = 1
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
end
endif
if stat = 0
stat = GetHTTPResponseReady(http)
else
if stat = 1 or stat = -1
if stat = 1
response$ = GetHTTPResponse(http)
rend# = timer()
gotmessages# = gotmessages# + 1
lastres# = (rend#-rstart#)
responcetimeavg# = responcetimeavg# + lastres#
stat = 2
else
rend# = timer()
gotmessages# = gotmessages# + 1
lastres# = (rend#-rstart#)
responcetimeavg# = responcetimeavg# + lastres#
stat = 2
// create new connection.
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
http = CreateHTTPConnection()
SetHTTPTimeout( http, 6000 )
SetHTTPHost( http, "www.playgames2.com", 0 )
response$ = "Reconnect..."
servererror# = servererror# + 1
endif
endif
// sent new data ?
if timer() - mytimer# > 0.3
// every second.
mytimer# = timer()
myvar$ = "f=1&c="+ str(mytimer#)
// emulate a normal data amount.
myvar$ = myvar$ + "|px=1.123456|py=13.123456|pz=13.123456|pax=13.123456|pay=13.123456|paz=13.123456|ps=shooting|psx=13.123456|psy=13.123456|psz=13.123456|lastdatetime=123456780"
SendHTTPRequestASync( http, "agk2.php" , myvar$ )
rstart# = timer()
stat = 0
endif
endif
Print( ScreenFPS() )
Print( str(stat) + ", Server response: " + response$ )
print( "AVG Responce time: " + str(responcetimeavg#/gotmessages#) + " , Last: " + str(lastres#) )
print( "Server errors: " + str( servererror# ) )
Sync()
loop
The php code agk2.php just response with the same data you sent but * 10 times to emulate a data flow.
best regards Preben Eriksen,