0

我正在 CentOS 6.2 上构建一个 C 套接字程序,如下所示。

  1. 服务器正在侦听来自所有客户端的连接请求。

  2. 建立连接后,客户端开始将日志数据发送到单个服务器。

问题是所有客户端都将日志数据发送到同一端口,这CLOSE_WAIT在客户端关闭连接时会出现问题。

在网上冲浪时,我读到我应该关闭套接字以终止“CLOSE_WAIT”连接,这意味着服务器不能再接受来自另一个客户端套接字的日志数据。

有没有办法杀死端口上的特定会话?如果不可能,我应该创建多服务器侦听器吗?

4

1 回答 1

2

The problem is all clients sends log data to the same port which makes CLOSE_WAIT issue when the client closes the connection.

No it doesn't. CLOSE_WAIT means that (i) the peer has closed his end of the connection, and (ii) the local system is waiting for the local application to do the same. It has nothing to do with 'to the same port', which is how all TCP services work.

I read that I should close socket to kill 'CLOSE_WAIT' connection

Correct.

which means the server can't accept log data from another client socket any more.

No it doesn't. That would happen if you closed the listening socket. You need to close the accepted socket, the one you got EOS from.

Is there any way to kill specific session on a port?

Close the socket.

If it's not possible, Should I create multi server listener?

Surely you have already done that?

You don't have any choice about this. If you receive end-of-stream when reading a socket, you can't read anything more from it. Ever.

于 2013-10-07T07:22:09.623 回答