dongmibeng5885 2014-09-05 21:44
浏览 19

too long

I'm implementing websockets for a chat system. The server.php is being invoked via ssh with php /www/server.php, and the first time it executes fine; but if the process is stopped (ctrl+z), this error is displayed after trying to invoke php /www/server.php again:

Warning: socket_bind(): unable to bind address [48]: Address already in use in /www/server.php

These are the contents of the /www/server.php file:

<?
$host = '10.10.0.103';
$port = '1337';

//Create TCP/IP sream socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

//reuseable port
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);

//bind socket to specified host
socket_bind($socket, 0, $port);

//listen to port
socket_listen($socket);

// ... etc

So, I have two questions:

  1. Can I reuse the same address / port after stopping the php /www/server.php job with a FLAG? Isn't SO_REUSEADDR supposed to reuse the same address/port?

  2. What are the best practices for this issue? Restarting the websockets server could be an everyday task, e.g.: after updating the contents of /www/server.php

Thanks for any tips!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?