What is the difference between socket communication and tcp communication?
The difference between socket communication and tcp communication: 1. The tcp protocol belongs to the transport layer protocol, while socket is an abstraction layer between the application layer and the transport layer; 2. A three-way handshake is required to establish a TCP connection; 3. Socket connections can maintain long connections; 4. TCP server and TCP client use socket communication, etc.
#The operating environment of this article: Windows 10 system, Dell G3 computer.
What is the difference between socket communication and tcp communication?
The difference between tcp and socket
## 1: tcp protocol
The tcp protocol belongs to the transport layer protocol (UDP also belongs to the transport layer protocol, but the UDP protocol is stateless). Establishing a TCP connection requires three handshakes, and disconnecting a TCP connection requires four waves. The mobile phone can use the networking function because the bottom layer of the mobile phone implements the TCP/IP protocol. You can use the mobile phone terminal to establish a TCP connection with the server through the wireless network. The TCP protocol can provide an interface to the upper-layer network, so that the transmission of upper-layer network data is established on an "undifferentiated" network. tcp requires three handshakes to establish a connection: Figure 1: Tcp connection three-way handshake diagram
Figure 2: Four wave waves when the tcp connection is disconnected
2: socket
We know that if two processes need to communicate, the most basic premise is to be able to uniquely identify a process. In local process communication, we can PID is used to uniquely identify a process, but PID is only unique locally. There is a high probability of PID conflict between two processes in the network. At this time, we need to find another way. We know that the IP address of the IP layer can uniquely identify the host, and The TCP layer protocol and port number can uniquely identify a process on the host, so we can use the IP address + protocol + port number to uniquely identify a process on the network. Figure 5: Schematic diagram of the socket communication system module
As you can see from the picture, the socket connection can maintain a long connection.
Figure 6: Basic socket client/server communication process diagram
Note that the socket connection can be actively closed by the client or the server.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What is the difference between socket communication and tcp communication?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article brings you relevant knowledge about php+socket, which mainly introduces IO multiplexing and how php+socket implements web server? Friends who are interested can take a look below. I hope it will be helpful to everyone.

How to reset tcp/ip protocol in win10? In fact, the method is very simple. Users can directly enter the command prompt, and then press the ctrl shift enter key combination to perform the operation, or directly execute the reset command to set it up. Let this site do the following. Let us carefully introduce to users how to reset the TCP/IP protocol stack in Windows 10. Method 1 to reset the tcp/ip protocol stack in Windows 10. Administrator permissions 1. We use the shortcut key win R to directly open the run window, then enter cmd and hold down the ctrl shift enter key combination. 2. Or we can directly search for command prompt in the start menu and right-click

TCP client A client sample code that uses the TCP protocol to achieve continuous dialogue: importsocket#Client configuration HOST='localhost'PORT=12345#Create a TCP socket and connect to the server client_socket=socket.socket(socket.AF_INET,socket .SOCK_STREAM)client_socket.connect((HOST,PORT))whileTrue:#Get user input message=input("Please enter the message to be sent:&

1. Socket programming based on TCP protocol 1. The socket workflow starts with the server side. The server first initializes the Socket, then binds to the port, listens to the port, calls accept to block, and waits for the client to connect. At this time, if a client initializes a Socket and then connects to the server (connect), if the connection is successful, the connection between the client and the server is established. The client sends a data request, the server receives the request and processes the request, then sends the response data to the client, the client reads the data, and finally closes the connection. An interaction ends. Use the following Python code to implement it: importso

The first step on the SpringBoot side is to introduce dependencies. First we need to introduce the dependencies required for WebSocket, as well as the dependencies for processing the output format com.alibabafastjson1.2.73org.springframework.bootspring-boot-starter-websocket. The second step is to create the WebSocket configuration class importorg. springframework.context.annotation.Bean;importorg.springframework.context.annotation.Config

The "connection-oriented" mentioned here means that you need to establish a connection, use the connection, and release the connection. Establishing a connection refers to the well-known TCP three-way handshake. When using a connection, data is transmitted in the form of one send and one confirmation. There is also the release of the connection, which is our common TCP four wave waves.

Common network communication and security problems and solutions in C# In today's Internet era, network communication has become an indispensable part of software development. In C#, we usually encounter some network communication problems, such as data transmission security, network connection stability, etc. This article will discuss in detail common network communication and security issues in C# and provide corresponding solutions and code examples. 1. Network communication problems Network connection interruption: During the network communication process, the network connection may be interrupted, which may cause

Solution to the problem that the php socket cannot be connected: 1. Check whether the socket extension is enabled in php; 2. Open the php.ini file and check whether "php_sockets.dll" is loaded; 3. Uncomment "php_sockets.dll".