sockets - PHP/UDP: Can write via UDP, but recieving data seams not possibleGet the solution ↓↓↓
I have this code which is running on php on my local mac:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $result = socket_connect($socket, $address, $port); $msg = "i"; $len = strlen($msg); socket_send($socket, $msg, $len, 0); socket_recv($socket, $buf, 512, 0); echo $buf; socket_close($socket);
The code works up to "socket_recv". Actually, when running a udp test app on the computer, I can see the answer from the udp server on the terminal screen of the app. However, the script itself is running for ever (I assume that it is waiting for input which never comes through the socket for some reason). I also tried to run the script on a local Webserver on a synology NAS. Same result.
(Same result with the UDP App obviously closed)
Problem solved by using this code. Apparently one has to close the socket after sending and open a new one for receiving. It seams to be a unique behaviour of this device (server):
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $bytes = socket_sendto($socket, $message, strlen($message), 0, "192.168.0.37", 7090); socket_close($socket); $message="curr 7700"; $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_bind($socket, '0.0.0.0', 7090); $from = ''; $port = 0; socket_recvfrom($socket, $buf, 512, 0, $from, $port); echo $buf . PHP_EOL;
People are also looking for solutions of the problem: object not found by the @paramconverter annotation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.