SOCK_RECV (client app) doesn't return -1 when server app has crashed

Previous topic - Next topic

FutureCow

I'm currently testing my board game's network mode and I'm trying to get all the bugs out of my code.

I'm running the "server" version of the app on one pc (no GLBasic, just running the .exe), and the "client" on the pc running GLBasic in debug mode.

The server stops after a couple of seconds if it doesn't get the right responses from the client (I've set up challenge/response communication to tell the client when to progress). Once the server has stopped executing though, my client (currently) sits in a loop checking for network messages and attempting to process them. After the server has stopped itself, any time the client runs a SOCK_RECV it is not returning a -1 length for error. Instead it's returning 0, and a GETLASTERROR command straight after the SOCK_RECV is returning Error : 0000 success.

My understanding is that SOCK_RECV should return -1 if there's a problem reading from the socket - and I think the socket closing would count as an error  :)

It's getting too late to write a test program here, but I'll try to write one tomorrow if noone has replied with a solution to catching the network dropout.

MrTAToad

I always took -1 to be either a sending error or an internal error of some description (corrupt buffers, socket closed etc).

You could check for a return value of 0, if you are using TCP - that should indicate if the server has disconnected, although its doubtful if it covers crashed servers.


Kitty Hello

Yes, crashed servers will act as if they were disconnected. TCP keeps some sort of heartbeat message.