search
HomePHP FrameworkSwooleDifferences between various swoole servers

Differences between various swoole servers

server.php                                                                                                                                                                                                                                            #A TCP server is created here to listen to the local port 9501. Its logic is very simple. When the client Socket sends a hello string through the network, the server will reply with a Server: hello string.

Server is an asynchronous server, so the program is written by listening to events. When the corresponding event occurs, the underlying layer will actively call back the specified function. For example, when a new TCP connection comes in, the onConnect event callback will be executed. When a connection sends data to the server, the onReceive function will be called back.

UDP server is different from TCP server. UDP has no concept of connection.

After starting the Server, the client can directly send data packets to the 9502 port monitored by the Server without Connect. The corresponding event is onPacket.

$clientInfo is client-related information, an array, including the client’s IP and port, etc. Call the $server->sendto method to send data to the client

Http server You only need to pay attention to the request response, so you only need to listen to one onRequest event.

This event will be triggered when a new HTTP request comes in. The event callback function has two parameters. One is the $request object, which contains request-related information, such as GET/POST request data.

The other is the response object. The response to the request can be completed by operating the response object. The $response->end() method means to output a piece of HTML content and end the request.

0.0.0.0 means monitoring all IP addresses. A server may have multiple IPs at the same time, such as 127.0.0.1 local loopback IP, 192.168.1.100 LAN IP, 210.127.20.2 external network IP, which can also be used separately Specify a listening port for IP9501. If it is occupied, the program will throw a fatal error and interrupt execution.

The WebSocket server is a long-connection server built on the Http server. The client will first send an Http request to shake hands with the server.

After the handshake is successful, the onOpen event will be triggered, indicating that the connection is ready. The $request object can be obtained in the onOpen function, which contains information related to the Http handshake, such as GET parameters, Cookie, Http header information, etc.

After the connection is established, the client and server can communicate in two directions.

When the client sends information to the server, the server triggers the onMessage event callback. The server can call $server->push() to send a message to a client (using the $fd identifier). The server can Set up the onHandShake event callback to handle the WebSocket handshake manually.

swoole_http_server is a subclass of swoole_server, with built-in support for Http. swoole_websocket_server is a subclass of swoole_http_server, with built-in support for WebSocket

The above is the detailed content of Differences between various swoole servers. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

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.