TCP-IP socket programming for network programming (1)

Source: Internet
Author: User

TCP-IP socket programming for network programming (1)

To communicate between two network programs, you need to establish a connection channel between them, which is composed of a quintuple.

Quintuple: (protocol, local IP address, local port number, remote IP address, remote port number)

Socket programming principles

Socket set Interface

Communication between network programs relies on socket interfaces.

For example, if the QQ program on host A needs to send A message to host B, the steps are as follows:

① The QQ messages on host A are sent to the socket on host.

② This socket is transmitted to the network interface card in host B through the network management software of host.

③ The network interface card of host B receives the message and then transmits it to the network management software of host B and then to the socket of host B.

④ Then, QQ in host B reads the information in socket.

Set interface category

① Stream set interface (SOCK_STREAM) reliable connection-oriented data transmission service (applicable to TCP)

② The SOCK_DGRAM interface does not have a two-way Data Transmission Service (using UDP) with unreliable connection)

③ The original interface (SOCK_RAM) is rarely used

Socket programming principles

① When the server calls the socket () function to start a service, it creates an interface set.

② Use the bind () function to bind a port to the socket.

③ Call the listen () function to listen to client requests

④ The client also calls the socket () function to wear a set of interfaces requesting services, and then calls the connect () function to request connections.

⑤ The server calls the accept () function to receive request connections, then reads data from the set interface using the recv () function, and calls the send () function to send data to the set Interface

6. Disable the set of interface resources


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.