PHP communicates with UDP using a fixed port number
阿神
阿神 2017-06-23 09:11:29
0
2
1231

Currently known server, ip192.168.10.1, port number 8123, language C , communication protocol udp
Note: The server only receives requests from clients with port number 8234

The code below was found online. It can send a successful request, but cannot receive a return value.
You can see with the packet capture tool that every time a request is sent, the port number on my side is dynamic, starting from about 49k, and increasing by 1 for each request.
The port number is incorrect, so the server will naturally not return a value to me.

function udpGet($sendMsg){  
    $handle = stream_socket_client("udp://192.168.10.1:8123", $errno, $errstr);  
    if( !$handle ){  
        die("ERROR: {$errno} - {$errstr}\n");  
    }  
    fwrite($handle, $sendMsg."\n");  
    $result = fread($handle, 1024);  
    fclose($handle);  
    return $result;  
}  
  
$result = udpGet('Hello World');  
echo $result;  

How to solve this problem? I checked some information, but did not find a solution.

阿神
阿神

闭关修行中......

reply all(2)
ringa_lee

https://stackoverflow.com/que...

I don’t want to say anything else, I just want to say:

You can use Google to search for this need,

The keyword is also very simple:

php udp set client port
阿神

UDP communication can only be sent but not returned, TCP should be used

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template