zoukankan      html  css  js  c++  java
  • 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:

    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.

  • 相关阅读:
    arcgis api for flex 开发入门
    Error #2148
    为Flex Builder设置测试服务器
    地图服务报 error #2035
    springMVC整理03--处理数据模型 & 试图解析器 & @ResponseBody & HttpEntity
    FastDFS安装与使用
    springMVC整理02--常用注解的使用
    springMVC整理01--搭建普通的工程
    Spring模块介绍
    spring05-Spring事务管理
  • 原文地址:https://www.cnblogs.com/yy1234/p/8079630.html
Copyright © 2011-2022 走看看