Sign in to follow this  
Wickeeed

fast question about tcp

Recommended Posts

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 ???

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this