Relationship between SOCKET and TCP/IP and HTTP

Source: Internet
Author: User
4.1 relationship between SOCKET and TCP/IP

Socket is an application interface, and TCP/IP is a network transmission protocol. Although the interfaces are the same, different protocols have different service properties. When creating a Socket connection, you can specify the transport layer protocol used. The Socket can support different transport layer protocols (TCP or UDP). When using the TCP protocol for connection, the Socket connection is a TCP connection. Soket is not necessarily related to TCP/IP. The Socket programming interface is designed to adapt to other network protocols. Therefore, the emergence of socket is only more convenient to use the TCP/IP protocol stack.

4.2 SOCKET usage of TCP/IP

Socket abstracts TCP/IP and forms several basic function interfaces. For example, create, listen, accept, connect, read, and write. If a program creates a socket and listens to port 80, it declares its possession of port 80 to the TCP/IP protocol stack. In the future, all TCP data packets destined for port 80 will be forwarded to this program (the program here, because the Socket programming interface is used, is first processed by the Socket Layer ). The so-called accept function abstracts the TCP connection establishment process. The accept function returns a socket that actually refers to the connection created this time. A connection contains two parts: the source IP address and the source port, and the source IP address and the target port. Therefore, accept can generate multiple different sockets, And the IP addresses and ports contained in these sockets remain unchanged. Only the source IP addresses and source ports change. In this way, these socket ports can all be 80, and the Socket layer can accurately identify the ownership relationship between the IP packet and the socket based on the source/destination pair, this completes the encapsulation of TCP/IP protocol operations!

4.3 relationship between SOCKET and HTTP

1) http-based mobile phones are supported, and socket is not necessarily supported.

2) http can only be a question-and-answer (request/response connection), and socket can communicate in two directions (after a URL is located, both parties can send and receive information, request/response is not required ).

3) The Socket may be blocked by the firewall, but http can pass through the firewall.

HTTP is a sub-Protocol Based on Socket communication. The Socket transmission and receiving information is free and can be defined by users. HTTP is based on the Socket protocol specification. Communication can only be performed in a specific format. Users can develop their own sub-protocols on HTTP, such as web browsing and webservice.

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.