Socket
- Socket is also called "socket"
- The two programs on the network realize the exchange of data through a two-way communication connection, one end of this connection is called a socket.
- Applications typically make requests to the network via "sockets" or respond to network requests
Elements of network communication
- The request on the network is to establish a connection through the socket and then communicate with each other
- IP address (Unique identification of host devices on the network)
- Port number (Locator)
- The logical address used to mark the process, and the marking of the different processes
- Valid ports: 0~65535, where 0~1024 is used by the system or reserved ports, it is recommended to use more than 1024 ports in development
- Transport protocol (how to interact)
- Rules of Communication
- Common protocols: TCP, UDP
Transport protocol: TCP&UDP
Socket Communication flowchart
Socket communication flowchart. png
Add:
1.HTTP the bottom is the connection through the socket to establish a communication pipeline to achieve data transmission
2.HTTP is a TCP Transport protocol (mode), it is a reliable, secure protocol
Implement the Socket monitoring method
(1) Using C language to implement,
(2) using the cocoaasyncsocket third box, the interior is a C package
- telnet command telnet host port/telnet 192.168.10.10 5288
- The 1.telnet command is a service that corresponds to a port on the connection server
Protocol on the socket Layer
- The protocol on the socket layer refers to the format of the data transfer
- HTTP protocol
Transport format: Suppose: This is the assumption that the actual HTTP format is not the case.
http1.1,content-type:multipart/form-data,content-length:188,body:username=zhangsan&password=123456
-
XMPP protocol, an Instant messaging protocol
- Extensible Message Processing Field Protocol) is an Extensible Markup Language (XML)-based protocol that is used for instant messaging (IM) and on-line on-site probing. This agreement may eventually allow Internet users to send instant messages to anyone else on the internet
-
Transfer format:
<from>zhangsan<from>
<to>lisi<to>
<body> eat together at night </body>
-
Custom Instant Messaging protocol, JSON format
{
"From": "Zhangsan",
"To": "Lisi",
"Body": "Eat Lunch Together"
}
Latest-ios sockets