gpt4 book ai didi

PHP socket_bind() : unable to bind address [10013]

转载 作者:行者123 更新时间:2023-12-03 11:55:06 25 4
gpt4 key购买 nike

我正在尝试与特定硬件建立 udp 套接字连接,该硬件在端口 7715 接收数据,将答案发送到 udp 端口​​ 7714,端口无法更改。下面的一段代码:

<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

if (!socket_bind($socket, '192.168.1.254', 7714)){
echo socket_strerror(socket_last_error($socket));
}

socket_connect($socket, '192.168.1.150', 7715);
if (!socket_listen($socket, 5)){
echo socket_strerror(socket_last_error($socket));
}

$arr = [0x23, 0x00, 0x0C, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06];
$checksum = 0x00 - array_sum($arr);
$str = implode(', ', $arr);

$eval = '$buffer = ' . "pack('c*', $str, $checksum);";
eval($eval);

socket_write($socket, $buffer);

防火墙禁用,Wireshark 显示,一切正常:

1 0.000000 192.168.1.254 192.168.1.150 UDP 54 65213 → 7715 Len=12

2 0.005611 192.168.1.150 192.168.1.254 UDP 78 7715 → 7714 Len=36



不知何故,PHP 可以将此套接字绑定(bind)到任何 udp 端口​​,但不能绑定(bind)到 7714。

Warning: socket_bind(): unable to bind address [10013]: An attempt was made to access a socket in a way forbidden by its access permissions.

Warning: socket_listen(): unable to listen on socket [10045]: The attempted operation is not supported for the type of object referenced.



有什么问题?

最佳答案

发现自己,udp端口7714被其他进程使用。

关于PHP socket_bind() : unable to bind address [10013],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47516340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com