About sockets, TCP/IP, HTTP, FTP, and network programming

Source: Internet
Author: User
Tags ack

Source: TaubonrenLinks: http://blog.jobbole.com/99694/

Since it is a network transmission, involving the interaction between several systems, the first thing to consider is how to accurately locate one or several hosts on the network, and how to carry out reliable and efficient data transmission. This will use the TCP/IP protocol.

1.1 TCP/IP protocol group

the TCP/IP Protocol (Control Protocol) is IP protocols for the network layer and the TCP protocol for Transport Layer composition. the IP layer is responsible for the location of the network host , the routing of Data transmission, the IP address can uniquely determine a host on the Internet. The TCP layer is responsible for the application-oriented reliable or unreliable data transmission mechanism , which is the main object of network programming.

TCP/IP is a protocol group that can be divided into three levels:Network layer, transport layer, and 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;HTTPis the application layer protocol, whose transmissions are packaged as TCP protocol transmissions. You can implement HTTP with a socket.

SOCKET is a programming API that implements the Transport layer protocol, which can be TCP , or it can be UDP.

1.2 TCP tcp-Transmission Control Protocol, providing aconnection oriented、ReliableOfbyte 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. When disconnected, both the server and the client can proactively initiate a request to disconnect a TCP connection.

TCP is aconnectivity-oriented protocols for reliable transmission。 With the TCP protocol transmission, a sequential error-free data stream is obtained. A connection must be established between the sender and the receiver's paired two sockets to communicate on the basis of the TCP protocol, and when a socket (usually a server socket) waits for a connection, the other socket can require a connection. Once the two sockets are connected, they can carry out two-way data transfer and both can send or receive operations.

TCP Features:TCP is a connection-oriented protocol,Connect via three handshake to remove connection when communication is complete, because TCP is a connection-oriented protocol,only for Point-to-point communication. and establishing a connection also consumes time and overhead. TCPno size limit for transfer datafor large data transfer. TCP is aa reliable Protocol, it ensures that the receiver can receive all the data sent by the sender in a complete and correct manner.

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, waiting for the server to confirm;Second handshake: The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, complete three handshake;

Applicable situation:

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


TCP has a strong vitality in network communications, such as remote Connection (Telnet) and file Transfer (FTP), which require the data to be reliably transmitted over an indefinite length. But reliable transmission is to pay a price, the correctness of the data content of the test must occupy the computer processing time and network bandwidth , so the efficiency of TCP transmission is not as high as UDP.

1.3 udpudp-User Datagram Protocol, is aNon-connectedSimple.for datagramsOfTransport Layer Protocol。 Udpdoes 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 very fast.

UDP is a non-connection-oriented protocol, each datagram is a separate information, including the full source address or destination address, it on the network with any possible path to the destination, so can reach the destination, the time to reach the destination and the correctness of the content is not guaranteed.

UDP Features:

UDP isfor no connectioncommunication protocol, UDP data includes the destination port number and the source port number information, because the communication does not need to connect, sobroadcast delivery can be implemented . UDP has a size limit when transmitting data,each transmitted datagram must be limited to within 64KB. UDP is aan unreliable protocol., the sender sends a datagram that does not necessarily reach the receiver in the same order.

Applicable situation:

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.


UDP is simple to operate and requires less monitoring, so it is often used for client/server applications in decentralized systems with high LAN reliability. For example, the video conferencing system, does not require audio and video data is absolutely correct, as long as the consistency can be guaranteed, in this case, it is obvious that using UDP is more reasonable.

1.4 Socketsocket is also commonly referred to as "sockets",used to describe the IP address and port, which is a handle to a communication chain。 The two programs on the network realize the exchange of data through a two-way communication connection, one end of this bidirectional link is called a socket, and a socket is determined only by an IP address and a port number. Applications typically make requests to the network through sockets or answer network requests. Socket is a very popular programming interface of TCP/IP protocol, but the type of protocol supported by socket is not only TCP/IP, so there is no necessary connection between the two. In the Java environment, socket programming mainly refers to the network programming based on TCP/IP protocol.


About sockets, TCP/IP, HTTP, FTP, and network programming

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.