fast question about tcp

Started by
2 comments, last by markr 19 years, 7 months ago
Hello all, i want to know how to check a tcp socket that dont have any data to read for errors. that is a problem for me cuz i use gametutorials-like-server-system, with FD_SET and select. my problem is that when a client is gone without "bye" message, how can i find him?? i guess i shuld get an error or something ? how can i check sockets in FD_SET for errors like this ???
Advertisement
well, if a client disconnects, you get a READ-event in select(). Then when you read from the socket, it returns a read of 0 bytes.

(it's the same if you try to write to the socket and write() or send() returns 0 - it means that the connection is closed)

is this what you were asking for?
thx, looks tike that, connect from server to client is closed but connect from client to server is still there and WAITING (1min long i guess), whys that ? it isnt a big problem but i cant use this port while its waiting.

i guess connection from client to server shuld be closed first because it used closesocket first??
If the socket is ready, and reading from it returns 0 bytes, that means the socket is closed.

If reading or writing to the socket returns an error other than EINTR or EWOULDBLOCK (Usually connection reset by peer), that means something has gone wrong.

In that case you should close the socket and release the client's resources. The socket is not usable after any error has occurred.

Mark

This topic is closed to new replies.

Advertisement