Socket Shutdown Disconnect Close Dispose的解释

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, Close without timeout is the same as Dispose.

If you use the using block on the socket, it will automatically call Dispose.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值