Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with network disconnections

Started by quarity2 Dec 26, 2006 at 5:13 AM 4 replies 750+ views
Original Post
quarity2
quarity2
I'm trying to add network on my game and it seems to work properly. I'm using server and client on the same game. I'm using winsock2 and are creating a windows application. But when a client disconnects, then the server and all the other clients hangs. I need a good way to tell if a client is active or if the server is disconnected. I'm using blocking sockets. The clients waits until they have received all data from the server. The server waits until it have received all data from every client.
Bob Janova
Bob Janova
You should never block your main thread on a read() call. There's no guarantee that a client will ever send any data, or that you will get told when a connection is lost. If you use blocking sockets, you should either do it in a separate thread or use the Windows version of select() (sorry, I forget what it's called) to find out if any data is available before trying to read from it.
Kylotan
Kylotan
Use select() to see when data is available. Otherwise you're going to be stuck. There's no surefire instant way of your computer knowing if a remote computer has disconnected uncleanly, is transmitting very slowly, or has been blown up.
quarity2
quarity2
Ok. I guess I could do that on the server side without and side-effect since everything is handled on the server side.

But the client can't continue the game, unless it have retrieved data from the server. Otherwise there would be a big 'jump' in the game. Since it's action-based, it retrieves data from the server every frame. (Although I could change it so it retrieves data for every game tic). So every game tic is important so that the game on the server doesn't have any advantages towards the game on the client.

Currently I'm only testing the network on the same computer. But using the real internet, how often could I actually retrieve data from the server? How should the network be handled on a action-based game?
hplus0603
hplus0603
You should not base game networking on request/reply. Action game networking needs to be stream based. The server needs to continually send out a stream of updates, which the client can listen to -- it's likely that the server will send out one or two additional updates during the time it just takes for a client command to go from the client to the server.
enum Bool { True, False, FileNotFound };
quarity2
quarity2
Ok, thanks alot for all your help. I need to remake the network design.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.