Socket programming based on TCP/IP protocol and UDP protocol __ programming

Source: Internet
Author: User
Tags set socket
Small Knowledge Points:

Socket: An interface between the application layer and the transport layer, one endpoint of the communication. Divided into streaming sockets (providing bidirectional ordered without duplication, no boundary record of the data stream)

and datagram Sockets (bidirectional, not guaranteed to be reliable and orderly and without duplication).

Port: integer identifier, 16 bit, 0~65535,1024 below is reserved bit, such as 80 is HTTP port, 21 is FTP communication port. 1024~49151 for use by general applications. 49152~65535 is a dynamic or private port.

IP: Internet Protocol

TCP/IP Model:

Application layer: (HTTP,FTP,TELNET,DNS,SMTP,POP3, etc.), corresponding to the three layers of the OSI model (application layer, presentation layer, Session layer)

Transport Layer: (TCP, UDP)

Network layer: (ip[Internetwork Protocol],icmp[Internet Message Control Protocol],igmp[internet Group Management Protocol])

Network interface layer (data link layer): Low two layer (data link layer and physical layer) corresponding to the OSI model

Calmly close: One side even closes the connection, but the other side can still read the data from the network stack. If a connection-oriented protocol does not support quiet shutdown, the connection is immediately interrupted and data is lost, as long as one side shuts down the communication, and the receiver cannot read the data. For TCP, the connection can be completely disconnected only if both sides of the connection perform one shutdown. socket programming based on TCP (connection-oriented)

TCP is a connection-oriented, reliable transport protocol

server-side programs:

1: Create socket (socket)

2: Bind the socket to a native address and port (BIND)

3: Set socket to listening mode, ready to receive customer request (listen)

4: Waiting for the arrival of the customer request, when the request arrives, accept the connection request, return a new socket corresponding to this connection (accept)

5: Communication with the returned socket and client (SEND/RECV)
6: Return, wait for another user's request

7: Close Socket

client program:

1: Create socket (socket)

2: Send a connection request to the server side (connect)

3: Communication with the server (recv/send)

4: Close Socket

socket programming based on UDP (non-connection oriented)

UDP is connectionless, unreliable transport protocol

server-side (receiving-side) programs:

1: Create socket (socket)

2: Bind the socket to a local address and port (BIND)

3: Waiting to receive data (RECVFROM)

4: Close Socket

Client (send-side) program:

1: Create socket (socket)

2: Send data (SendTo)

3: Turn off sockets

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.