SOCKET, TCP/UDP, HTTP, FTP

Source: Internet
Author: User
Tags file transfer protocol

SOCKET, TCP/UDP, HTTP, FTP (1) TCP/UDP, SOCKET, HTTP, FTP analysis TCP/IP is a protocol group, which can be divided into three levels: network layer, transmission layer, and application 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, and its transmission is packaged as TCP protocol transmission. You can use SOCKET to implement HTTP. SOCKET is a programming API for implementing the transport layer protocol. It can be TCP or UDP. (2) differences between Socket connection and HTTP connection [Socket] because a Socket connection is a TCP connection, once a Socket connection is established, both parties can send data to each other, the connection is closed. However, in actual network applications, communication between the client and the server often needs to traverse multiple intermediate nodes, such as routers, gateways, and firewalls, by default, most firewalls disable connections that are not active for a long time and cause the Socket connection to be disconnected. Therefore, the network needs to be notified through polling that the connection is active. [Http] the HTTP protocol is an application built on the TCP protocol. The HTTP connection uses the "request-response" method. Not only do you need to establish a connection during the request, in addition, the server can reply to data only after the client sends a request to the server. After the request ends, the connection is released. The process from establishing a connection to closing a connection is called "One connection ". As HTTP actively releases connections after each request ends, HTTP connections are short connections. To keep the client program online, you must continuously initiate connection requests to the server. The common practice is to immediately get no data, and the client also keeps sending a "keep connection" request to the server at a fixed time, the server replies to the client after receiving the request, indicating that the client is "online ". If the server cannot receive a request from the client for a long time, the client is considered to be "offline". If the client cannot receive a response from the server for a long time, the network is considered disconnected. HTTP is based on the request/response model. First, the customer establishes a TCP link with the server and sends a request to the server. The request contains the request method, URI, Protocol version, and related MIME-style messages. The server responds to a status line that contains the Protocol version of the message, a success and failure code, and related MIME-style messages. [Applicable] in many cases, the server needs to actively push data to the client to ensure real-time and synchronous data between the client and the server. If both parties establish a Socket connection, the server can directly transmit data to the client. If both parties establish an HTTP connection, the server must wait until the client sends a request before sending the data back to the client. Therefore, the client periodically sends a connection request to the server, which can not only be kept online, at the same time, it is also "asking" whether the server has new data. If yes, it will send the data to the client. [SOCKET principle] (1) socket concept: socket is the cornerstone of communication and the basic operation unit for network communication that supports TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process. It contains five types of information required for network communication: the protocol used for connection, the IP address of the local host, and 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 uses the transport layer for data communication, TCP may encounter concurrent services for multiple application processes at the same time. Multiple TCP connections or multiple application processes may need to transmit data through the same TCP port. To differentiate different application processes and connections, many computer operating systems provide Socket interfaces for applications to interact with TCP/IP protocols. The application layer and the transport layer can use Socket interfaces to distinguish between processes or network connections of different applications to implement concurrent data transmission services. (2) establish a socket connection: Establish a Socket connection requires at least one pair of sockets, one running on the client, called ClientSocket, And the other running on the server, called ServerSocket. The connection process between sockets is divided into three steps: server listening, client requests, and connection confirmation. Server listening: the server socket does not locate the specific client socket, but is waiting for connection. It monitors the network in real time and waits for the client connection request from the client: the client socket initiates a connection request. The target to be connected is the server socket. Therefore, the client socket must first describe the socket of the server to be connected, point out the address and port number of the socket on the server, and then submit a connection request to the socket on the server. Connection Confirmation: when the server socket monitors or receives a connection request from the client socket, it responds to the request from the client socket and creates a new thread, send the description of the server socket to the client. Once the client confirms the description, both parties establish a connection. The server socket continues to be in the listening status, and continues to receive connection requests from other client sockets. (3) when creating a SOCKET connection between a Socket connection and a TCP connection, you can specify the transport layer protocol used. The Socket can support different transport layer protocols (TCP or UDP ), when a TCP connection is used, the Socket connection is a TCP connection. (3) TCP and UDP [concept] TCP-Transmission Control Protocol, which provides connection-oriented and 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 data can be transmitted. TCP provides timeout resend, discard duplicate data, test data, traffic control, and other functions to ensure data can be transferred from one end to the other. Ideally, once a TCP connection is established, the TCP connection will remain until either of the two parties closes the connection. When a TCP connection is disconnected, both the server and client can initiate a request to disconnect the TCP connection UDP-User Datagram Protocol, which is a simple datagram-oriented transport layer protocol without connection. UDP does not provide reliability. It only sends the data from the application to the IP layer, but it cannot guarantee that the data can reach the destination. Because UDP does not need to establish a connection between the client and the server before transmitting the datagram, and there is no timeout and re-transmission mechanism, the transmission speed is very fast [applicable] the packets sent by TCP have serial numbers, after receiving the packet, the other party should give a feedback. If the packet has not received the feedback for a certain period of time, it will automatically execute timeout and resend. Therefore, the biggest advantage of TCP is reliability. Generally, tcp udp is a message-oriented protocol for webpage (http), email (SMTP), remote connection (Telnet), and file (FTP) transmission. No connection is required during communication, data transmission is naturally unreliable. UDP is generally used for multi-point communication and real-time data services, such as voice broadcast, video, QQ, and TFTP (simple file transfer), SNMP (Simple Network Management Protocol), RTP (Real-Time Transfer Protocol) RIP (routing information protocol, such as report stock market, aviation information), DNS (Domain Name explanation ). Focus on speed and smoothness. [Three-way handshake for TCP connections] To understand TCP, you must know "three-way handshake, four-way handshake". The so-called three-way handshake is the connection that must be established before sending data. It is called three-way handshake, it starts sending after the handshake is finished, which means connection-oriented. First handshake: the client sends the syn Packet (syn = j) to the server and enters the SYN_SEND status, waiting for confirmation from the server. Second handshake: the server receives the syn packet, you must confirm the customer's SYN (ack = j + 1) and send a SYN Packet (syn = k), that is, the SYN + ACK packet. At this time, the server enters the SYN_RECV status; the third handshake: the client receives the server's SYN + ACK package and sends the ACK (ack = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the ESTABLISHED status, complete three handshakes. (4) File Transfer Protocol (FTP) is the Protocol for transferring files from two computers on the TCP/IP network, FTP is one of the earliest protocols used on the TCP/IP network and the INTERNET. It belongs to the application layer of the network protocol group. The FTP client can send commands to the server to download files, upload files, and create or change directories on the server.
 

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.