The difference between webSocket and Socket

1. Introduction to the concepts of webSocket and Socket

1. Socket is translated as socket. Socket is an abstraction layer between the application layer and the transport layer. It abstracts the complex operations of the TCP/IP layer into several simple interfaces for the application layer to call to realize the process in the network. communication.

2. The WebSocket protocol is a new network protocol based on TCP. It belongs to the application layer protocol like the http protocol. It is a technology that enables two-way real-time communication between the client and the server.

2. The difference between webSocket and Socket

1. The difference in principle:

Socket is a transmission control layer protocol, and WebSocket is an application layer protocol.

Socket is an intermediate software abstraction layer for communication between the application layer and the TCP/IP protocol family. It is a set of interfaces (not a protocol, a layer abstracted for the convenience of using TCP or UDP, which is located between the application layer and the transmission control layer. set of interfaces).

In the design mode, Socket is actually a facade mode, which hides the complex TCP/IP protocol family behind the Socket interface. Use the TCP/IP protocol to establish a TCP connection. (The TCP connection relies more on the underlying IP protocol, and the IP protocol connection relies on lower layers such as the link layer.)

WebSocket is a typical application layer protocol.

2. Different degrees of flexibility:

WebSocket is easier to use, while Socket is more flexible. Socket is an intermediate software abstraction layer for communication between the application layer and the TCP/IP protocol family, and it is a set of interfaces.

In the design mode, Socket is actually a facade mode, which hides the complex TCP/IP protocol family behind the Socket interface. For users, a set of simple interfaces is all, and Socket organizes data to meet the specified protocol.

In order for the application program of host A to communicate with the application program of host B, a connection must be established through Socket, and the establishment of Socket connection must require the underlying TCP/IP protocol to establish a TCP connection. Establishing a TCP connection requires the underlying IP protocol to address hosts on the network.

The IP protocol used by the network layer can help us find the target host according to the IP address, but there may be multiple applications running on one host, so how to communicate with the specified application must use the address of TCP or UPD, which is the port number to specify. In this way, a Socket instance can uniquely represent the communication link of an application on a host.

WebSocket is different, it is a complete application layer protocol, including a set of standard API.

3. Different transmission levels:

Socket is the interface of the transmission control layer. Users can operate the underlying TCP/IP protocol family communication through Socket.

Socket in the network is not a protocol, but a layer of API abstracted to use TCP and UDP. It is an abstraction layer between the application layer and the transport layer. Socket is an encapsulation of TCP/IP; HTTP is a car, which provides a specific form of encapsulation or display data; Socket is an engine, which provides the ability of network communication.

Under the Unix philosophy that everything is a file, Socket is an implementation of the "open-read/write-close" mode. The server and the client each maintain a "file". After the connection is established and opened, they can write to their own file. The content is for the other party to read or read the content of the other party, and the file is closed when the communication ends.

WebSocket is a protocol for full-duplex communication over a single TCP connection. WebSocket makes data exchange between client and server easier, allowing the server to actively push data to the client.

In the WebSocket API, the browser and the server only need to complete an HTTP handshake, and a persistent connection can be created directly between the two, and two-way data transmission can be performed.

3. OSI seven-layer protocol

OSI is an open communication system interconnection reference model, which is a very well-defined protocol specification. The OSI model has a 7-layer structure, from top to bottom are 7 application layer 6 presentation layer 5 session layer 4 transport layer 3 network layer 2 data link layer 1 physical layer.

Layer 7 protocol example
application layer For example HTTP, SMTP, SNMP, FTP, Telnet, SIP, SSH, NFS, RTSP, XMPP, Whois, ENRP
presentation layer For example XDR, ASN.1, SMB, AFP, NCP
session layer For example ASAP, TLS, SSH, ISO 8327 / CCITT X.225, RPC, NetBIOS, ASP, Winsock, BSD sockets
transport layer For example TCP, UDP, RTP, SCTP, SPX, ATP, IL
Network layer 例如IP、ICMP、IGMP、IPX、BGP、OSPF、RIP、IGRP、EIGRP、ARP、RARP、 X.25
data link layer For example Ethernet, Token Ring, HDLC, Frame Relay, ISDN, ATM, IEEE 802.11, FDDI, PPP
physical layer such as lines, radio, fiber optics, carrier pigeons

Guess you like

Origin blog.csdn.net/cst522445906/article/details/117199630