现在的位置: 首页 > 综合 > 正文

How to release the port of TCP Client immediately when the connection is disconnect with the TCP server. – TCP 客户端与 TCP 服务器断开连接后

2013年12月01日 ⁄ 综合 ⁄ 共 386字 ⁄ 字号 评论关闭

How to release the port of TCP Client immediately when the connection is disconnect with the TCP server. - TCP 客户端与 TCP 服务器断开连接后,如何立刻释放端口

 

 

在 TCP C/S 模式下,当 TCP 客户端想断开的时候,不能用 shutdown 和 closesocket 与 TCP 服务器断开,只有让 TCP 服务器端主动断开(TCP 客户端被动断开),TCP 客户端的端口才能立刻被释放。

 

举个例子:

 

如果 TCP Client 要想与 TCP Server 断开 TCP 连接,TCP Client 可以向 TCP Server 发一个 “Quit” 字符串命令,

 

TCP Server 检测到 TCP Client 发送了 “Quit” 字符串,就 closesocket

 

TCP Client 侧的 socket 也会触发断开,这样 TCP Client 端口就可以立刻被释放

抱歉!评论已关闭.