C#中Socket关闭 Close、Dispose、Shutdown、Disconnect
An answer on StackOverflow made me think I have finally reached some glimpse of an understanding. Then I went testing for a bit and here's the summary of a newbie's view. Please correct me if I'm wrong because this is based on inference, not expertise.
Shutdown
Shutdown disables the Send and/or Receive methods, depending on the provided argument. It doesn't disable the underlying protocol handling and it never blocks.
If Send is disabled, it also queues up a zero-byte send packet into the underlying send buffer. When the other side receives this packet, it knows that your socket will no longer send any data.
If Receive is disabled, any data the other side might be trying to send will be lost.
If Receive is disabled without disabling Send, it just prevents the socket from receiving data. Since no zero-byte packet will be sent, the other side won't know anything about it until it tries to send something, and only if the socket's protocol requires acknowledging.
Disconnect
First, Disconnect does the equivalent of Shutdown(SocketShutdown.Both).
Then it blocks, waiting for two things:
- For all the queued-up send data to be sent.
- For the other side to acknowledge the zero-byte packet (if applicable to the underlying protocol).
If you call Disconnect(false), system resources will be freed.
Close
Close frees system resources. May abruptly stop sending queued-up data. If called with the argument, will wait for the data to be sent, but only up to the specified timeout.
Dispose
Dispose is same as the Close overload without the timeout argument. To be more precise, Closewithout timeout is the same as Dispose.
If you use the using block on the socket, it will automatically call Dispose.
C#中Socket关闭 Close、Dispose、Shutdown、Disconnect的更多相关文章
- 关闭钩子(shutdown hook)的作用以及在Tomcat中的使用
在很多实际应用环境中,当用户关了应用程序时,需要做一些善后清理工作,但问题是,用户有时并不会按照推荐的方法关闭应用程序,很有可能不做清理工作,例如在Tomcat的部署应用中,通过实例化一个Server ...
- socket关闭状态问题
下面是对 譬如 “CLOSE_WAIT” 现象的一些解释: 主动关闭方和被动方经历的状态:FIN_WAIT_1(主动关闭一方): 当SOCKET在ESTABLISHED状态时,它想主动关 闭 ...
- linux中socket的理解
对linux中socket的理解 一.socket 一般来说socket有一个别名也叫做套接字. socket起源于Unix,都可以用“打开open –> 读写write/read –> ...
- 操作系统底层原理与Python中socket解读
目录 操作系统底层原理 网络通信原理 网络基础架构 局域网与交换机/网络常见术语 OSI七层协议 TCP/IP五层模型讲解 Python中Socket模块解读 TCP协议和UDP协议 操作系统底层原理 ...
- python中socket模块详解
socket模块简介 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.socket通常被叫做"套接字",用于描述IP地址和端口,是一个通信 ...
- Linux查看系统中socket状态
当我们打开的socket数量很多时,netstat就会变得慢了,有什么办法可以快速查看系统中socket状态? IPv4: $ cat /proc/net/sockstat sockets: used ...
- (转)python标准库中socket模块详解
python标准库中socket模块详解 socket模块简介 原文:http://www.lybbn.cn/data/datas.php?yw=71 网络上的两个程序通过一个双向的通信连接实现数据的 ...
- 第一篇 网站基础知识 第4章 Java中Socket的用法
第4章 Java中Socket的用法 4.1 普通Socket的用法 Java中的网络通信是通过Socket实现的,Socket分为ServetSocket和Socket两大类,ServetSocke ...
- Ubuntu中启用关闭Network-manager网络设置问题!
Ubuntu中启用关闭Network-manager网络设置问题! [Server版本] 在UbuntuServer版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改/etc/net ...
随机推荐
- WinPcap是用于网络封包抓取的一套工具
WinPcap是用于网络封包抓取的一套工具,可适用于32位的操作平台上解析网络封包,包含了核心的封包过滤,一个底层动态链接库,和一个高层系统函数库,及可用来直接存取封包的应用程序界面. Winpcap ...
- MySQL输入密码后闪退
刚刚我遇到这个问题,服务里MySQL是启状态的,所以我求助百度,发现很多种说法,我试了几个,还是不行,后来想起来我的密码不对,于是换了正确的密码试了一下,没毛病,进去了. 所以输入密码闪退时,首先确定 ...
- L245
The State Council will lay down new rules that aim to make management compatible with internationall ...
- 虚拟机提示:无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件
虚拟机提示:无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件 Win 10 vmware12 无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件. ...
- SpringSecurity入门例子及遇到的问题解决
最近学习<Spring 实战>学习到了SpringSecurity,觉得书本上的例子过于复杂,而且不喜欢它基于java配置,更喜欢用xml文件进行配置 于是在极客学院网上学习,感觉挺不错的 ...
- Python 特殊关系
class Foo: def __init__(self): # 初始化操作 print("我是init, 我是老二") print("初始化操作. 在创建对象的时候自动 ...
- MySQL的架构与历史
MySQL的最主要特性是它的存储引擎架构,这种架构设计将查询处理以及其他系统任务和数据的存储/提取相分离. MySQL最上层服务是一些如连接处理,授权认证,安全等. MySQL的核心服务功能大部分度在 ...
- tomcat多实例的端口设置
需要改4个端口 8080 8009 8005 8443 8080改成8081 8005改成8105 8009改成8109 8443 改成8543
- Android内核sys_setresuid() Patch提权(CVE-2012-6422)
让我们的Android ROOT,多一点套路. 一.简单套路 CVE-2012-6422的漏洞利用代码,展示了另一种提权方法.(见附录) 这也是一个mmap驱动接口校验导致映射任意内核地址的洞.将内核 ...
- jsp-servlet(2)响应HTML文档-书籍管理系统
基础知识预备: 目标: 构建一个书籍管理系统,实现以下功能. 功能: 1 图书信息查询,(查) 2 书籍管理:添加书籍 3 书籍管理:修改书籍信息 4 书籍管理:删除书籍 一.预备工作 Book{ ...