Network Programming FAQs under Linux

Source: Internet
Author: User
Tags ack

Network program abnormally exited without core file generation

This happens when the connection side is closed, but the other side is also doing a send operation on the connection handle, so that the process of the send operation receives the SIGPIPE signal, and the default behavior is to exit directly without generating the core. To avoid quitting, generally add signal (Sigpipe, sig_ign) at startup to ignore this error.

Send-side send succeeds, but the receiver fails recv

Send just means that the data copy to the send buffer, does not mean that the data reached the recv, if this time the network problem, the opposite does not receive data.

How to let the receiving party know how long the sender sends the data each time

Two different ways

1. And the IP protocol similar to each piece of data sent before stitching a fixed length of Baotou, Baotou storage data length type information, the recipient side Recv2, the first to receive Baotou, the second time according to the length of the Baotou application space to collect data

2. Similar to the HTTP header, the special marker symbol is the end, HTTP is 2 \r\ n

Service-side address reuse issues

The service end multiplicity is told that the port is occupied because the server has actively called the close operation. The port of the active disconnecting party will be in the TIME_WAIT state for a short time after disconnection, when the port cannot be reused, the solution is to set so_reuseaddr in the SetSockOpt function to ensure the reuse of the address.

Why does it appear time_wait

Four waves in the process, the active disconnection received from the opposite fin package to reverse an ACK packet reply (This is the fourth wave), after the ACK to wait for 2 time_wait (60S) time to close their own, because the ACK packet will appear in the case of packet loss, if present, Opposite due to not receive an ACK may also re-hair fin package, and ack->fin this one back the longest time is exactly 2 time_wait time, so the active disconnect in waiting 2 time_wait time after the seizure of fin to indicate that the ACK packet is normal to the opposite connection

When does the close_wait state appear?

The passive shut-off party receives the opposite fin packet to send its own fin packet this time the network will be in close_wait state, but this period of time is relatively short, unless it is their own side of the network exception can not shut down the connection.

Listen's backlog settings

Listen inside maintenance of 2 queues, one is already connected to complete the queue, the length of the backlog, one is not complete the connection queue, the length of the backlog/2,accept is completed queue handle, if the accept is not timely may cause the queue full, So the listen will reject the connection.

Network Programming FAQs under Linux

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.