How the C # Socket server side determines client disconnects

Source: Internet
Author: User

Using the poll method in the socket class, you can.

Socket client//If it has already been created, connect to the server-side of the socket to the clients object.

We just need the client. Poll (10,selectmode.selectread) judge on the line. As long as the return true is. You can assume that the client has been disconnected.

The Poll method will check the status of the Socket . Specifies the SelectMode parameter of the SelectMode.::. Selectreadto determine if the Socket is readable. Specify selectmode.::. Selectwriteto determine if the Socket is writable. Use SelectMode..::. Selecterror Detection error condition. Poll will block execution within a specified period of time (in microseconds). If you want to wait for the response indefinitely, set microseconds to a negative integer. If you want to check the status of multiple sockets, you may wish to use the Select method.

This method does not detect certain types of connection problems, such as a network cable outage or a remote host shutting down unexpectedly. You must try to send or receive data to detect these types of errors.

How the C # Socket server side determines client disconnects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.