I have a simple network setup that takes the position of an object and sends it to the ‘listening’ client to use as its own position. The problem is that whenever the client doesn’t hear anything from the server for a while, the logic use skyrockets and the game halts until the next position update from the server. Anyone see anything wrong with my logic in this setup? This image has everything that’s going on in the scene.
This is because the function RecvFrom is blocking, as in it will halt the game until it receives the data. There is a different way to set it up, I’ll get back to you with the code(Am just posting this now so you might figure it out in the mean time :D). Also, if I don’t within a few days, please remind me, I have a habit of forgetting :P.
mmh thanks for the tip. I’ll see what I can do with that. And sure, I’ll remind you again in a few days if I don’t get it, lol.
I don’t understand your problem. Your code doesn’t look bad however this is not the way to do networking in the game engine. You are opening (and closing) sockets for every frame this way. This is not friendly for your system. You should create code that sets up a socket and maintains it, and code that uses the socket to send or receive.
Best method is to use threads actually. Look at this BGE webserver to see how it’s done there.
that is a lot to take in. will have a look
If threads is too hard, use timeout on the socket. Timeout will allow your socket to stop working for a while so the game loop can carry on, and is very simple to use. sock.timeout(0.1), will have your socket listen for 1/10 sec.
Threads are obviously more fluid but they also put a lot of logical strain on the game, since they run all the time in most cases!
No no, just set the thread to non blocking.
Sent from my Nexus 5 using Tapatalk
Open this and check it out
OOOhhh. That’s good!
I got my thing to work but this is much more convenient. Mind if I use this?
Sure, why not.
Nice job on this.