Refresh masterserver in thread

BlitzMax Forums/BlitzMax Programming/Refresh masterserver in thread

Arska(Posted 2015) [#1]
Hi. I am experience some delay when i refresh my game server with master server. Here is code:
Local stream:TStream
stream=OpenStream(masterServerURL+"?action=refreshserver")
If Not stream Return False
stream.close()
			
Print "Server refreshed with masterserver!"


What would be best way to do that without getting lag in game? Threads? I haven't used threads in any way so is it even possible in this case?


Derron(Posted 2015) [#2]
Yes threads.


Problem is the latency you get when talking to remote URIs.

Just do it in a threaded manner, else you will run into trouble as soon as "masterServerURL" runs under heavy load and response times vary from milliseconds to minutes.

OpenStream will block the whole application until it times out somehow.


Maybe Bruceys curl module does something threaded (behind the scenes - in c-files) and has some kind of "readAvail()" method you check from time to time after you have requested a data fetch from the masterUrl.


It does not matter how - but the solution is to make the request threaded/asynchronous as you else have to wait for an answer whose reply-time cannot get guaranteed.


bye
Ron


Arska(Posted 2015) [#3]
Thanks, i got it working with threads.