开发者

c++ detect if the client closed the connection (multi sockets)

In my program I have several sockets on the server. Each socket has its own port. I tried to detect if the client closed the connection with:

signal(SIGPIPE, sig_pipe);

But I have the problem that I don't k开发者_如何学编程now on which socket the connection was closed. Is there some method to get it to know?

More about code: In main program I started 3 Sockets on different ports. Accept, receive and send for each socket I put in one thread. So I have 3 threads at the end.

Thank you.


You should setup SIGPIPE to be ignored (see sigaction(2)) and handle EPIPE error code from write(2) and the likes.

Note, that reading zero bytes from TCP socket is the real indication of the other side closing the connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜