Swoole learning: how to create a server with swoole


How to create a server using spool

  • Create TCP server
$serv = new swoole_server("", 9501); 
  • Create UDP server
$serv = new swoole_server("", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP); 
  • Creating web server
$http = new swoole_http_server("", 9501);
  • Create websocket server
$ws = new swoole_websocket_server("", 9502);
  • be careful
1、swoole_ http_ Server inherits from spool_ server
2、swoole_ websocket_ Server inherits from spool_ http_ server
3. The parameter host refers to IP. If you fill in a domain name, it's OK. But it's not only the domain name that can be accessed, but it can be accessed as long as it's bound with the same IP as the domain name. Therefore, the effect of filling in a domain name is the same as that of filling in IP. Just fill in IP (internal and external IP / external IP / local IP / all IP)

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]