Tcp,ip,http,socket Differences and linkages

Source: Internet
Author: User
Tags ack file transfer protocol

First look at the chart below to try to show the location of different TCP/IP and other protocols in the original OSI model

7 Application Layer such as HTTP, SMTP, SNMP, FTP, Telnet, SIP, SSH, NFS, RTSP, XMPP, Whois, ENRP
6 Presentation Layer such as XDR, ASN.1, SMB, AFP, NCP
5 Session Layer for example ASAP, TLS, SSH, ISO 8327/ccitt x.225, RPC, NetBIOS, ASP, Winsock, B SD sockets
4 Transport Layer For example TCP, UDP, RTP, SCTP, SPX, ATP, IL
3 Network layer For example IP, ICMP, IGMP, IPX, BGP, OSPF, RIP, IGRP, EIGRP, ARP, RARP, &NB Sp X.
2 Data link layer For example Ethernet, Token Ring, HDLC, Frame Relay, ISDN, ATM, IEEE 802.11, F DDI, PPP
1 physical layer For example line, radio, fiber, homing pigeon

TPC/IP Protocol is a Transport layer protocol, which mainly solves how data is transmitted in the network, and HTTP is the application layer protocol, which mainly solves how to wrap the data. regarding the relationship between TCP/IP and HTTP protocol, the network has a relatively easy to understand: "When we transmit data, we can only use the (Transport Layer) TCP/IP protocol, but in that case, if there is no application layer, it will not be able to identify the data content, if you want to make the transmitted data meaningful, You must use the Application layer protocol, there are many application layer protocols, such as HTTP, FTP, Telnet, etc., you can also define the application layer protocol. The web uses the HTTP protocol as an application-layer protocol to encapsulate HTTP text information and then send it to the network using TCP/IP as the Transport layer protocol. ”

The term TCP/IP stands for Transmission Control Protocol/Internet Protocol, which refers to a series of protocols. "IP" represents an Internet protocol in which TCP and UDP use the protocol to transfer packets from one network to another network. Put IP imagined as a highway, it allows other protocols to travel on it and find the exits of other computers. TCP and UDP are "trucks" on highways, and the goods they carry are like HTTP, File Transfer Protocol FTP and so on. So that means HTTP (Hypertext Transfer Protocol) is the protocol that leverages TCP to transfer information between two computers, usually Web servers and clients. The client initiates an HTTP request to the Web server using a Web browser, and the Web server sends the requested information to the client.

The socket is the encapsulation and application of the TCP/IP protocol (at the programmer level). It can also be said that the TPC/IP protocol is the Transport Layer protocol, mainly to solve how the data in the network transmission, and HTTP is the application layer protocol, mainly to solve how to package the data. We usually say the most socket is what, in fact, the socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol. In fact, the socket is not necessarily associated with the TCP/IP protocol. The socket programming interface is designed to adapt to other network protocols as well. So, the advent of sockets just makes it easier for programmers to use the TCP/IP protocol stack, which is an abstraction of the TCP/IP protocol, thus forming some of the most basic function interfaces we know, such as Create, listen, connect, accept, send, Read and write, and so on. The network has a paragraph about the socket and TCP/IP protocol relationship is easier to understand: "TCP/IP is a protocol stack, like operating system operation mechanism, must be specific, but also to provide external operating interface." This is like the operating system will provide a standard programming interface, such as the Win32 programming interface, TCP/IP should also provide the interface for programmers to do network development, this is the socket programming interface .

In fact, the transport layer TCP is based on the network layer of IP protocol, and the application layer of the HTTP protocol is based on the transport layer of the TCP protocol, and the socket itself is not a protocol, as mentioned above, it just provides a TCP or UDP programming interface.

Here are some of the important concepts that are often encountered in a written test or interview and are summarized here.

One. What is a three-time handshake for a TCP connection

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, and the handshake is completed three times.
The data is not included in the packets that are delivered during the handshake, and the client and server formally begin transmitting the data after the three handshake is complete. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively closes the connection. When disconnected, both the server and the client can initiate a request to disconnect the TCP connection, and the disconnection process requires a "four handshake" (the process is not fine-grained, that is, the server interacts with the client and finally determines the disconnection)

Two. To establish a network connection using a socket

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.

1. 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 connection request.

2. 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.

3. 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.

Three. Features of HTTP links

The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol.

The most notable feature of an HTTP connection is that each request sent by the client requires a server loopback response, and the connection is actively released after the request has ended. The process from establishing a connection to closing a connection is called a "one-time connection."

Four. The difference between TCP and UDP

You should be able to understand that TCP and UDP are the transport layer protocols used by FTP,HTTP and SMTP. Although both TCP and UDP are used to transmit other protocols, they have a significant difference: TCP provides guaranteed data transfer, and UDP does not. This means that TCP has a special mechanism to ensure that data is safe from one endpoint to another without error, and UDP does not provide any such assurance.

1. TCP is link-oriented, although the network's insecure instability determines how many times the handshake can not guarantee the reliability of the connection, but the TCP three handshake at least (in fact, to a large extent guaranteed) to ensure the reliability of the connection, and UDP is not a connection-oriented, UDP transmission data before the connection with the other party, the data received is not sent to confirm the signal, the sender does not know whether the data will be properly received, of course, there is no need to resend, so that UDP is a non-connected, unreliable data transmission protocol.

2. Also due to the characteristics of 1, so that the cost of UDP more small data transmission rate is higher, because there is no need to send and receive data confirmation, so UDP real-time better.

Know the difference between TCP and UDP, it is not difficult to understand why the use of TCP transmission protocol MSN than UDP transmission file slow, but can not say that QQ communication is not safe, because the programmer can manually verify the data sent and received by UDP, For example, the sender of each packet number and then by the receiver to verify AH what, even so, UDP because the package on the underlying protocol does not adopt a TCP-like "three-time handshake" to achieve the TCP can not achieve the transmission efficiency.

Organized from: (http://hi.baidu.com/qiaoyuetian/blog/item/1f32d5df42eeb6056327985c.html)

Tcp,ip,http,socket Differences and linkages

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.