Socket programming is the programming interface provided by the transport layer to the application layer. It is a bridge between the application layer and the transport layer. Using Socket programming, you can develop client and server applications, communicate on the local network, and also Can communicate globally via the Internet.
1. Introduction to socket programming
The so-called socket is usually also called "socket", which is used to describe IP addresses and ports. A handle to the communication chain. Applications usually make requests to the network or respond to network requests through "sockets". The network applications we develop are located at the application layer. TCP and UDP are transport layer protocols. How to use the transport layer services at the application layer? Between the application layer and the transport layer, sockets are used for separation.
The socket is like a small opening opened by the transport layer for the application layer. The application sends data to the remote through this small opening, or receives data from the remote; and within this small opening, that is, the data enters this After the port, or before the data comes out of this port, we don't know or need to know, and we don't care about how it is transmitted. This is the work of other levels of the network.
Socket is actually a programming interface provided by the transport layer to the application layer. The transport layer provides a logical channel from process to process based on the network layer, while the application layer process uses the transport layer to communicate with a certain process on another host. Socket is the bridge between the application layer and the transport layer. Using Socket programming, you can develop client and server applications, communicate on the local network, and communicate globally through the Internet.
2. What happens when two computers use sockets to establish a TCP connection
The server instantiates a ServerSocket object, indicating communication through the port on the server. The server calls the accept() method of the ServerSocket class, which waits until a client connects to the given port on the server. While the server is waiting, a client instantiates a Socket object, specifying the server name and port number to request a connection. The constructor of the Socket class attempts to connect the client to the specified server and port number. If communication is established, a Socket object is created on the client to communicate with the server. On the server side, the accept() method returns a new socket reference on the server that is connected to the client's socket.
The above is the detailed content of What is socket programming. 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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use