Home >Backend Development >PHP Tutorial >PHP listens to WebSocket, which can be accessed locally but not from the external network.
Firewall status OK:
Listening port: 2015
<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.
Firewall status OK:
Listening port: 2015
<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?