Home >Backend Development >PHP Tutorial >PHP listens to WebSocket, which can be accessed locally but not from the external network.

PHP listens to WebSocket, which can be accessed locally but not from the external network.

WBOY
WBOYOriginal
2016-10-19 10:40:542083browse

Firewall status OK:
PHP listens to WebSocket, which can be accessed locally but not from the external network.
Listening port: 2015

PHP listens to WebSocket, which can be accessed locally but not from the external network.

<code class="php">   $this->socket = socket_create(AF_INET,SOCK_STREAM, SOL_TCP);
   socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR,true);
   socket_bind($this->socket, 0 , $this->port);
   //监听端口
   socket_listen($this->socket);
   socket_getsockname($this->socket, $ip,$port);
   printf("Server Open %s:%d\n",$ip,$port);</code>

ws://127.0.0.1: 2015 and ws://192.168.1.101: 2015 can both be created.
Using external IP will cause the link to time out.

Reply content:

Firewall status OK:
PHP listens to WebSocket, which can be accessed locally but not from the external network.
Listening port: 2015

PHP listens to WebSocket, which can be accessed locally but not from the external network.

<code class="php">   $this->socket = socket_create(AF_INET,SOCK_STREAM, SOL_TCP);
   socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR,true);
   socket_bind($this->socket, 0 , $this->port);
   //监听端口
   socket_listen($this->socket);
   socket_getsockname($this->socket, $ip,$port);
   printf("Server Open %s:%d\n",$ip,$port);</code>

ws://127.0.0.1: 2015 and ws://192.168.1.101: 2015 can both be created.
Using external IP will cause the link to time out.

Is this your own PC, or a cloud server?

Computers at work or home need to do port mapping on the router. Otherwise, when accessing the company’s external network IP, there are so many machines on the network, why should we connect to yours?

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