I'm trying to make an udp socket connection to a specific hardware, which receives data at port 7715, sends answers to udp port 7714, ports can't be changed. Piece of code below:
<?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);
Firewall disabled, Wireshark shows, that everything is OK:
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
Somehow, PHP can bind this socket to any udp port, but not to 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.
What can be wrong?