search
HomePHP FrameworkSwooleDoes swoole support multiple ports and different protocols?

Does swoole support multiple ports and different protocols?

Swoole-1.8.0 adds support for multi-port mixed protocols. Server can listen to multiple ports, and each port can be set with different protocol processing methods (set) and callback functions (on). SSL/TLS transport encryption can also be enabled only for specific ports. (Recommended Learning: SWOOLE Video Tutorial )

Unclicable SET method, set the monitor port of the protocol processing option, default to inherit the setting of the main server

## on method, sets the listening port of the callback function. The callback function of the main server is used by default.

The object type returned by the listening port is swoole_server_port

The swoole_server_port object of the listening port can call the set and on methods. The usage method is exactly the same as swoole_server

The listening port can only set a few specific options, and can only set event callback functions related to data sending and receiving

The callback functions of different listening ports are still the same Worker Executed in the process space

The main server is WebSocket or Http protocol. The newly monitored TCP port will inherit the protocol settings of the main server by default. The set method must be called separately to set the new protocol to enable the new protocol

Listen to the new port

$port1 = $server->listen("127.0.0.1", 9501, SWOOLE_SOCK_TCP);
$port2 = $server->listen("127.0.0.1", 9502, SWOOLE_SOCK_UDP);
$port3 = $server->listen("127.0.0.1", 9503, SWOOLE_SOCK_TCP | SWOOLE_SSL);

Set the network protocol

$port1->set([
    'open_length_check' => true,
    'package_length_type' => 'N',
    'package_length_offset' => 0,
    'package_max_length' => 800000,]
);
$port3->set([
    'open_eof_split' => true,
    'package_eof' => "\r\n",
    'ssl_cert_file' => 'ssl.cert',
    'ssl_key_file' => 'ssl.key',]
);

The above is the detailed content of Does swoole support multiple ports and different protocols?. 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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft