您现在的位置是:首页 > 文章详情 网站首页文章详情
linux系统搭建websocket注意事项
- 1486
- 0
- 2020-04-24 10:11:09
- PHP语言
这里讲述自己的两个不同的服务器搭建的过程 服务器1
西部数码服务器:ubuntu-14.04。外网ip:211.129.205.111 内网ip:192.168.205.41
把代码上传到指定的网站。运行服务器文件,正常运行和监听。一切顺利。 服务器2
阿里云服务器:centos 7。外网ip:121.68.26.22 内网ip:172.28.219.158
在把代码上传到指定的网站后,运行websocket终端的时候,总是报下面的这个错误。ip改用可以用来监听的外网ip。
[root@houxin socket]# php server.php
PHP Warning: socket_bind(): unable to bind address [99]: Cannot assign requested address in /www/wwwroot/socket/websocket.class.php on line 64
Warning: socket_bind(): unable to bind address [99]: Cannot assign requested address in /www/wwwroot/socket/websocket.class.php on line 64
开始监听: 121.68.26.22 : 8000 总是报socket_bind()这个函数绑定出现错误。之前上网查找总是找不到什么原因。 而且在服务器1上就可以正常使用。 这下懵逼了。 经过一番网络的查询,发现这样的一个解答。
You cannot bind to the external IP, you have to bind to the internal IP, and setup a rule to allow that port so when they connect to the external IP and port, it gets redirected to the internal IP.
于是尝试着把服务器的创建websocket的ip改成内部ip后。 果然成功了。 在此提醒自己,也给大家做个示范。由于服务器的环境不一样,所以我们要尝试多种途径的解决方法。
上一篇: linux端口查看以及端口解除占用
下一篇: mysql根据经纬度获取附近的商家