What happens if a client connected through a Socket has a bad lag ?
Let’s say i call socket.read() from the TCP server, and the client writes some stuff on the network pipe, but his connection is laging for 1 or 2 minutes. What will happen ? Will the read fail ? Or will it wait ?
I’m not sure if it’s even possible, but i’m playing online chess on FICS server and sometimes it seems to happen from my point of view (I’m only a user of this chess server).
I’m asking this because i’m working on an online game and i’d like to handle such cases one way or another. But first I need to know if:
- it can happen
- it can be detected
Thanks
I’d advise not relying solely on setting the
SO_TIMEOUTvariable but rather add application-level heartbeats between your client and server. If either the client or server does not receive a heartbeat message within a specified time (e.g. within twice the heartbeat frequency) it should sever the connection, and in the client’s case attempt a reconnect.Using a heartbeat mechanism also allows you to measure the lag by monitoring the delay in receiving heartbeat messages on each end.