dongshen2903 2012-07-12 10:00
浏览 23

如何使用php反复读取本地端口?

I have searched a lot on this topic and tried a lot of thingd but still i'm stuck.

I have an ec2 instance on which another instance is sending some data through tcp on a specific port. I am using the following code..

  $host = "x.x.x.x";
    $port = 2048;


    $socket = socket_create(AF_INET, SOCK_STREAM, 0)  ;

if (!socket_setopt($socket, SOL_SOCKET, SO_REUSEADDR, 1)) 
{
        echo socket_strerror(socket_last_error($socket));
        exit;
} 
    $result=socket_bind($socket, $host, $port);
    $result = socket_listen($socket, 3);

    $spawn = socket_accept($socket);

    $input = socket_read($spawn, 84);

echo $input;

    socket_close($spawn);
    socket_close($socket);

Sometimes it runs , sometimes it doesn't , it gives error at socket_bind():

"socket_bind(): unable to bind address [98]: Address already in use"

I'v looked a lot on this but nothing has worked...

If someone comes upt with something.. plz help..!

thanx mayur

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计