Ios development diary 11-http and socket, ios11-httpsocket

Source: Internet
Author: User

Ios development diary 11-http and socket, ios11-httpsocket

Today, the blogger has a need for network development and encountered some difficulties. I would like to share with you the hope to make common progress.

Today, I would like to share with you the differences between http and socket. For specific network protocols, please refer to Baidu

1. http connection: an http connection is a short connection. A client sends a request to the server. After the server responds, the connection will be disconnected.

Simply put, the web pages you browse (the URLs start with http: //) are transmitted to your browser over http, whereas http is based on socket. Socket is a set of interfaces for tcp and udp protocols.

HTTP: Simple Object Access Protocol, corresponding to the application layer. HTTP is based on TCP connections.

Tcp protocol: corresponding to the transport layer

IP protocol: corresponds to the network layer

TCP/IP is the transport layer protocol, which mainly solves how data is transmitted over the network. HTTP is the application layer protocol and mainly solves how to package data.

Socket is the encapsulation of TCP/IP protocol. Socket itself is not a protocol, but an interface (API) called. Through Socket, we can use TCP/IP protocol.

2. socket Connection: A socket connection is a persistent connection. Theoretically, once a connection is established between the client and the server, the connection will not be automatically disconnected. However, due to various environmental factors, the connection may be disconnected, for example: if the server or client host is down, the network is faulty, or data transmission is not performed between the two for a long time, the network firewall may disconnect the connection to release network resources. Therefore, when no data is transmitted in a socket connection, heartbeat messages must be sent to maintain the connection ~~ The specific Heartbeat message format is defined by the developer.

We already know that processes in the network communicate through sockets. What is socket? Socket originated from Unix, and one of the basic philosophies of Unix/Linux is "Everything is a file". You can use the "open-> read/write-> close" mode to operate. My understanding is that Socket is an implementation of this mode, and socket is a special file.

3. some socket functions are the operations (read/write IO, open, and close) on them. When we transmit data, we can only use the (Transport Layer) TCP/IP protocol, however, without the application layer, the data content cannot be identified. To make the transmitted data meaningful, you must use the application layer protocol. There are many application layer protocols, for example, HTTP, FTP, and TELNET, you can also customize the application layer protocol. The WEB uses HTTP as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network.

1) Socket is an interface programmed for TCP and UDP. You can use it to establish TCP connections. TCP and UDP protocols belong to the transport layer.

Http is an application layer protocol, which is also based on the TCP protocol.

(HTTP is a car that provides a specific form of encapsulation or display data; Socket is an engine that provides network communication capabilities .)

2) Socket is the encapsulation of TCP/IP protocol. Socket itself is not a protocol, but an interface (API) called. Through Socket, we can use TCP/IP protocol. The emergence of Socket only makes it easier for programmers to use the TCP/IP protocol stack. It is an abstraction of the TCP/IP protocol, thus forming some of the most basic function interfaces we know.

Related Article

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.