A brief analysis of TCP/UDP,SOCKET,HTTP,FTP protocol

Source: Internet
Author: User
Tags ack socket ftp client file transfer protocol ftp protocol port number
(a) A brief analysis of Tcp/udp,socket,http,ftp

TCP/IP is a protocol group that can be divided into three levels: the network layer, the transport layer, and the application layer:

Network layer: IP protocol, ICMP protocol, ARP protocol, RARP protocol, and BOOTP protocol

Transport layer: TCP protocol and UDP protocol

Application layer: FTP, HTTP, TELNET, SMTP, DNS, and other protocols


HTTP is an application-layer protocol whose transmissions are packaged as TCP protocol transmissions. You can implement HTTP with a socket.

A socket is a programming API that implements the Transport layer protocol, either TCP or UDP.


(b) Socket connection differs from HTTP connection

"Socket"

Since the socket connection is usually a TCP connection, once the socket connection is established, the communication parties can start sending data content to each other until the two sides are disconnected. However, in real network applications, the client-to-server communication often needs to traverse multiple intermediary nodes, such as routers, gateways, firewalls, and so on, most firewalls will turn off long inactive connections and cause the Socket connection to be disconnected, so it needs to be polled to tell the network that the connection is active.

"Http"

HTTP protocol is an application based on TCP protocol, the HTTP connection uses "Request-response" method, not only need to establish a connection in the request, but also require the client to make a request to the server, the server side can reply to the data. After the request is finished, the connection is released actively. The process from establishing a connection to closing a connection is called a "one-time connection." Because HTTP is actively releasing the connection after each request ends, the HTTP connection is a "short connection", which requires constant connection requests to the server to maintain the client program's online status. As a general practice, there is no need to obtain any data immediately, and the client will keep a "keep-connected" request to the server at regular intervals, and the server responds to the client after receiving the request, indicating that the client is "online". If the server can not receive the client's request for a long time, it is considered that the client "offline", if the client cannot receive a reply from the server for a long time, it is considered that the network has been disconnected.

"Where applicable"

In many cases, the server side is required to proactively push data to the client, keeping the client and server data in real time and in sync. At this time, if the two sides established a socket connection, the server can directly transfer data to the client ;

if the two sides establish an HTTP connection, the server needs to wait until the client sends a request to send the data back to the client , so the client periodically sends a connection request to the server, not only to remain online, but also to "ask" the server for new data. Pass data to the client, if any.

"SOCKET principle"

(1) socket (socket) Concept:

Socket (socket) is the cornerstone of communication and is the basic operating unit of network communication supporting TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process and contains five kinds of information that must be used for network communication: the protocol that the connection uses, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol port of the remote process.

When the application layer communicates data through the transport layer, TCP encounters a problem that provides concurrent services for multiple application processes at the same time. Multiple TCP connections or multiple application processes may require data to be transmitted over the same TCP protocol port. To differentiate between different application processes and connections, many computer operating systems provide a socket (socket) interface for applications interacting with the TCP/IP protocol. The application layer can communicate with the transport layer through the socket interface, differentiate the communication from different application processes or network connections, and realize the concurrent service of data transmission.

(2) Establishing a socket connection:

Establishing a socket connection requires at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket.

The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.

Server monitoring: Server-side sockets do not locate specific client sockets, but are waiting for the status of the connection, real-time monitoring network status, waiting for the client's connection request

Client request: Refers to the client's socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.

Connection confirmation: When a server-side socket hears or receives a connection request from a client socket, it responds to a client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the two sides formally establish the connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.

(3) Socket connection and TCP connection

When you create a socket connection, you can specify the transport layer protocol used, which can support different transport layer protocols (TCP or UDP), which is a TCP connection when a connection is made using the TCP protocol.


(iii) TCP and UDP

" concept "

TCP---Transmission Control Protocol, providing a connection-oriented, reliable byte-stream service. Before the customer and the server Exchange data with each other, a TCP connection must be established between the two parties before the data can be transferred. TCP provides time-out re-send, discard duplicate data, test data, flow control and other functions to ensure that data can be transmitted from one end to the other. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively shuts down the connection. Server and client can proactively initiate a request to disconnect a TCP connection when disconnected
UDP---User Datagram Protocol, is a simple non-connected Transport layer protocol for datagrams. UDP does not provide reliability, it simply sends the application to the IP layer's datagram, but does not guarantee that it will reach its destination. Because UDP does not have to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as time-out retransmission, the transmission speed is fast
"Where applicable"
TCP sends the packet has the serial number, the other party receives the packet to give a feedback, if has not received the feedback to automatically perform the time-out resend, therefore the TCP biggest advantage is reliable . General Web page (HTTP), Mail (SMTP), remote connection (Telnet), file (FTP) transfer is used with TCP
UDP is a message-oriented protocol, communication does not need to establish a connection, the transmission of data is naturally unreliable,UDP is generally used for multipoint communication and real-time data services , such as voice broadcast, video, QQ, TFTP (Simple File transfer), SNMP (Simple Network Management Protocol), RTP (Real-time delivery protocol) RIP (Routing Information protocol such as reporting stock market, aviation information), DNS (Domain name interpretation). Pay attention to the smooth speed.
"Three-time handshake for TCP connections"
To understand TCP, be sure to know "three times handshake, four times goodbye" so-called three times handshake, is to send data before the connection must be established to call three times handshake, shook hands before the beginning of the hair, which is the meaning of connection-oriented.
First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waits for the server to confirm; second handshake: The server receives the SYN packet, must confirm the customer's SYN (ACK=J+1), and also sends a SYN packet (syn=k), That is, the Syn+ack packet, when the server enters the SYN_RECV state, the third handshake: the client receives the server's Syn+ack package, sends the acknowledgement packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter ESTABL ished status, complete three handshake.

(4) FTP

The File Transfer Protocol (Files Transfer Protocol, FTP) is the protocol that transmits files to two computers on a TCP/IP network, and FTP is one of the earliest protocols used on TCP/IP networks and the Internet, which belongs to the application layer of the Network protocol group. The FTP client can issue commands to the server to download files, upload files, and create or change directories on the server.



from:http://blog.csdn.net/sunny243788557/article/details/19904349

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.