How to release the port of TCP Client immediately when the connection is disconnect with the TCP ser

编程知识 更新时间:2023-05-02 19:05:23

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

更多推荐

How to release the port of TCP Client immediately when the connection is disconn

本文发布于:2023-04-28 04:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/cd38475267ef1e15a22c976af33c091b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   服务器   TCP   Client   release

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107661文章数
  • 27233阅读数
  • 0评论数