Linux TCP/IP Programming

Source: Internet
Author: User
The general steps for TCP programming servers are as follows:
1. Create a socket and use the function socket ();
2. Set the socket property. Use the setsockopt () function. * optional.
3. Bind the IP address, port, and other information to the socket, and use the function BIND ();
4. Enable the listener and use the listen () function ();
5. Use the accept () function to receive connections from the client ();
6. send and receive data using the send () and Recv () functions, or read () and write () functions ();
7. disable network connections;
8. Disable the listener;

The common steps for TCP programming clients are as follows:

1. Create a socket and use the function socket ();
2. Set the socket property. Use the setsockopt () function. * optional.
3. Bind the IP address, port, and other information to the socket. Use the BIND function (). * optional
4. Set the IP address and port of the Peer to be connected;
5. Connect to the server and use the function connect ();
6. send and receive data using the send () and Recv () functions, or read () and write () functions ();
7. disable network connections;

 

The general steps for UDP programming on the server side are:

1. Create a socket and use the function socket ();
2. Set the socket property. Use the setsockopt () function. * optional.
3. Bind the IP address, port, and other information to the socket, and use the function BIND ();
4. receive data cyclically. Use the recvfrom () function ();
5. disable network connections;

The general steps for UDP programming clients are as follows:

1. Create a socket and use the function socket ();
2. Set the socket property. Use the setsockopt () function. * optional.
3. Bind the IP address, port, and other information to the socket. Use the BIND function (). * optional
4. Set attributes such as the IP address and port of the peer;
5. Send data using the sendto () function ();
6. Disable the network connection;

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.