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 ...
随机推荐
- SQL-18 查找当前薪水(to_date='9999-01-01')排名第二多的员工编号emp_no、薪水salary、last_name以及first_name,不准使用order by
题目描述 查找当前薪水(to_date='9999-01-01')排名第二多的员工编号emp_no.薪水salary.last_name以及first_name,不准使用order byCREATE ...
- offSet().left 与position().left的区别
offSet().left是针对整个当前文档的所说的偏移: position().left是对于父元素来说的:
- Android开发 ---基本UI组件3:单选按钮、多选按钮、下拉列表、提交按钮、重置按钮、取消按钮
Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个用户注册按钮 <?xml version="1.0" encoding=&q ...
- Gym - 100971J (思维+简单bfs)
题目链接:http://codeforces.com/gym/100971/problem/J J. Robots at Warehouse time limit per test 2.0 s mem ...
- mysql 数据库关于增加用户权限的问题
一新建用户 ----------- 二首先修改权限必须在电脑cmd 中运行 开设的权限 主要就是 1 所有库的 *.* 2 所有的表 db.* 3所有的字段db.t1 ...
- 初识Linux------虚拟机VM三种配置网络的解说
桥接模式: 相当于在物理主机与虚拟机网卡之间架设了一座桥梁,从而可以通过物理主机的网卡访问外网. NAT模式: 让 VM 虚拟机的网络服务发挥路由器的作用,使得通过虚拟机软件模拟的主机可以通过物理主 ...
- 惊不惊喜, 用深度学习 把设计图 自动生成HTML代码 !
如何用前端页面原型生成对应的代码一直是我们关注的问题,本文作者根据 pix2code 等论文构建了一个强大的前端代码生成模型,并详细解释了如何利用 LSTM 与 CNN 将设计原型编写为 HTML 和 ...
- kbmMWUnidac直接SQLServer
UniDAC支持SQLServer直联了,当时就测试过在kbmMW中用直联方式,结果不尽人意,kbmMWServer在执行sql时会出地址错误,就一直没有进一步测试.今天听xalion说,是因为当直联 ...
- ChinaCock界面控件介绍-CCGridPictureEditor
CCGridPictureEditor如其名,网格图片编辑控件,实现利用一个网格来显示多张图片的缩略图,这是一个非常实用的控件,实现类似微信朋友圈中发布多张图片的功能. 在没有这个控件之前,我都是用D ...
- easyUI datagrid值转义
数据库表里面字段的值想用另一种命名形式展示,如1是 是,2是 否 解决方法: 用到formatter ,{field:'params', title:'参数', width:100, sort ...