For some reason, even the TCP connection of Matrix1 Utils have problems, in this case, random crashes when receiving data.
This is an example of the code I use to forward and request data for my game to the server I have:
Connection = NEW CONNECT SOCKET( IPAddress, ECHO_PORT, TIMEOUTCONNECTION)
if Connection <> 0
SET SOCKET NO DELAY Connection,1
if SEND SOCKET STRING( Connection, "message" ) <= 0
Abort("Unable to transmit")
endif
SHUTDOWN SOCKET SEND Connection
ReturnStr = RECV SOCKET STRING$( Connection )
if SOCKET ERROR() > 0
Abort("Unable to receive")
endif
SHUTDOWN SOCKET RECV Connection
DELETE SOCKET Connection
endif
I have set some crash logging functions between any action of this code (connect, send, receive etc) and when the game crashes it Always crashes when the command "RECV SOCKET STRING$" is called.
I use to set the TIMEOUTCONNECTION to 50 or 100 ms (if you don't use a timeout a request could take too much time and the game stutters too much, at least with a timeout is limited), but I will probably implement a dynamic value (if is too low obviously miss the communication, usually below 25 ms, if too high stutters so much when trying to connect, so it's better to miss a communication if it takes for example 300-500 ms, as at this time there should be other communications to be done and the old ones are useless).
I call this function every 200 ms, so the game updates the server 5 times per second.
Sometimes the game crashes after a few seconds, but most of the times after minutes, and in rare cases after 10 minutes.
Another problem I wish to fix is how to have the communication with the server without let the game wait for it, otherwise it stutters a bit (it's not smooth), and obviously lower the fps because every frame lose time for the connection.