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, Close
without 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 ...
随机推荐
- SQL-26 (二次分组)汇总各个部门当前员工的title类型的分配数目,结果给出部门编号dept_no、dept_name、其当前员工所有的title以及该类型title对应的数目count
题目描述 汇总各个部门当前员工的title类型的分配数目,结果给出部门编号dept_no.dept_name.其当前员工所有的title以及该类型title对应的数目countCREATE TABLE ...
- ORA-02049: 超时: 分布式事务处理等待锁
java.sql.SQLSyntaxErrorException: ORA-02049: 超时: 分布式事务处理等待锁 ORA-06512: 在 "HECDEV.BGT_JOURNAL_BA ...
- SharePoint Framework 在Visual Studio Code中调试你的托管解决方案
博客地址:http://blog.csdn.net/FoxDave 上一篇介绍了如何在本地调试你的SharePoint Framework解决方案,本篇介绍如何调试你的SharePoint Onl ...
- excel的操作
python可以对excel进行写的操作,读的操作和修改的操作,做不同的功能需要导入不同的模块 1.对 excel进行写的操作 import xlwt book=xlwt.Workbook() #新建 ...
- TensorFlow函数:tf.zeros_like
tf.zeros_like函数 tf.zeros_like( tensor, dtype=None, name=None, optimize=True ) 定义在:tensorflow/python/ ...
- day 35 关于线程
并发编程之协程 对于单线程下,我们不可避免程序中出现io操作,但如果我们能在自己的程序中(即用户程序级别,而非操作系统级别)控制单线程下的多个任务能在一个任务遇到io阻塞时就切换到另外一个任务去计 ...
- myql update from 语句
(6)UPDATE 语句与 SELECT 语句中的 TOP 子句一起使用对来自表 authors 的前十个作者的 state 列进行更新 UPDATE authors SET state = 'ZZ' ...
- FileInputStream类与FileOutputStream类
FileInputStream类是InputStream类的子类.他实现了文件的读取,是文件字节输入流.该类适用于比较简单的文件读取,其所有方法都是从InputStream类继承并重写的.创建文件字节 ...
- ES6 声明变量的6种方法
ES5 只有两种声明变量的方法:var命令和function命令. ES6除了添加let和const命令,后面章节还会提到,另外两种声明变量的方法:import命令和class命令.所以,ES6 一共 ...
- weex--手机调试
Weex Playground 我的是小米应用市场,没有搜索到,不过这是官方的二维码,我是扫描这个二维码下载的.