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

89 篇文章 0 订阅
37 篇文章 0 订阅

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 端口就可以立刻被释放

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值