About socket TCP wire break re-connect

Source: Internet
Author: User

This problem has plagued me several times, has not had time to study, today studies.

    • First write a simple socket TCP program, the connection is successful and then shut down the server and then use the client various operations to see what the situation

Tests show

(1) The client is already connected, and when the server closes the program, the client calls the Send function to fail, WSAGetLastError () returns 10054 (the remote host forcibly shuts down an existing connection)

(2) The client is already connected, when the client closes the program, the server calls the RECV function to receive the failure, WSAGetLastError () returns 10054 (the remote host forcibly closes an existing connection), when the socket for this client calls the Select function, Will immediately return to readable.

(3) The client is already connected, and when the server closes the program, the client calls the RECV function to receive the failure, WSAGetLastError () returns 10054

    • About client wire break re-connect

The rough practice is that when the client calls send or recv fails, then WSAGetLastError () determines the error number and then closes the socket. Create a socket again. Then do a connect operation.

Attached below is a one-to-many chat supported by the source server that I wrote based on socket streaming sockets. Socket-related communications are all used with Windows APIs. Used for beginners ' learning.

SOURCE download

About socket TCP wire break re-connect

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.