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:

  1. For all the queued-up send data to be sent.
  2. 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的更多相关文章

  1. 关闭钩子(shutdown hook)的作用以及在Tomcat中的使用

    在很多实际应用环境中,当用户关了应用程序时,需要做一些善后清理工作,但问题是,用户有时并不会按照推荐的方法关闭应用程序,很有可能不做清理工作,例如在Tomcat的部署应用中,通过实例化一个Server ...

  2. socket关闭状态问题

    下面是对 譬如  “CLOSE_WAIT” 现象的一些解释: 主动关闭方和被动方经历的状态:FIN_WAIT_1(主动关闭一方): 当SOCKET在ESTABLISHED状态时,它想主动关     闭 ...

  3. linux中socket的理解

    对linux中socket的理解 一.socket 一般来说socket有一个别名也叫做套接字. socket起源于Unix,都可以用“打开open –> 读写write/read –> ...

  4. 操作系统底层原理与Python中socket解读

    目录 操作系统底层原理 网络通信原理 网络基础架构 局域网与交换机/网络常见术语 OSI七层协议 TCP/IP五层模型讲解 Python中Socket模块解读 TCP协议和UDP协议 操作系统底层原理 ...

  5. python中socket模块详解

    socket模块简介 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.socket通常被叫做"套接字",用于描述IP地址和端口,是一个通信 ...

  6. Linux查看系统中socket状态

    当我们打开的socket数量很多时,netstat就会变得慢了,有什么办法可以快速查看系统中socket状态? IPv4: $ cat /proc/net/sockstat sockets: used ...

  7. (转)python标准库中socket模块详解

    python标准库中socket模块详解 socket模块简介 原文:http://www.lybbn.cn/data/datas.php?yw=71 网络上的两个程序通过一个双向的通信连接实现数据的 ...

  8. 第一篇 网站基础知识 第4章 Java中Socket的用法

    第4章 Java中Socket的用法 4.1 普通Socket的用法 Java中的网络通信是通过Socket实现的,Socket分为ServetSocket和Socket两大类,ServetSocke ...

  9. Ubuntu中启用关闭Network-manager网络设置问题!

    Ubuntu中启用关闭Network-manager网络设置问题! [Server版本] 在UbuntuServer版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改/etc/net ...

随机推荐

  1. const & define & inline

    0x01  const & define区别 宏定义#define发生在预编译期,而const,enum定义的常量发生在编译期,两者的重要差别在于编译期里的变量是进符号表的,而预编译期的宏是简 ...

  2. 从SharePoint 2013迁移到SharePoint Online - 评估工具

    博客地址:http://blog.csdn.net/FoxDave 今天想跟大家分享一款从SharePoint 2013迁移到SharePoint Online时的评估工具:SharePoint ...

  3. r-mq实现顺序消费,不重复消费

    根据订单号,同一订单号的消息,会被发送到同一个topic下的同一个queue,发送端的有序,会导致topic中消息的有序,而consumer和queue是一对多?的关系.可以保证topic中的有顺序的 ...

  4. php优秀框架codeigniter学习系列——common.php

    文件位于system/core/common.php,是框架核心文件. 该文件中定义了一系列的函数,都是框架运行中经常需要用到的.下面逐一介绍. is_php /** * Determines if ...

  5. SpringSecurity入门例子及遇到的问题解决

    最近学习<Spring 实战>学习到了SpringSecurity,觉得书本上的例子过于复杂,而且不喜欢它基于java配置,更喜欢用xml文件进行配置 于是在极客学院网上学习,感觉挺不错的 ...

  6. uniDAC 7.2.14直联sqlite存在问题

    用最新的uniDAC 7.2.14,设置Direct=True,直联sqlite数据库,发现Release状态下出错,Debug没有问题. 改成Direct=False,则没有问题. 警告!    各 ...

  7. SQL注入之Sqli-labs系列第十二关

    开始挑战第十二关(Error Based- Double quotes- String) 12点半了,不困,继续,继续,继续 先看看页面,通常的使用单引号等进行操作,看看啥么情况先 咦,出现错误信息了 ...

  8. Spring Boot 揭秘与实战(七) 实用技术篇 - StateMachine 状态机机制

    文章目录 1. 环境依赖 2. 状态和事件 2.1. 状态枚举 2.2. 事件枚举 3. 状态机配置4. 状态监听器 3.1. 初始化状态机状态 3.2. 初始化状态迁移事件 5. 总结 6. 源代码 ...

  9. stack-protector-strong

    Improve protection against stack buffer overflows Much like its predecessor, stack-protector, stack- ...

  10. php获取真实ip地址(转)

    REMOTE_ADDR只能获取访问者本地连接中设置的IP,如中南民族大学校园网中自己设置的10.X.XXX.XXX系列IP,而这个函数获取的是局域网网关出口的IP地址, 如果访问者使用代理服务器,将不 ...