search

Home  >  Q&A  >  body text

PHP communicates with UDP using a fixed port number

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.

阿神阿神2746 days ago1233

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-06-23 09:13:29

    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

    reply
    0
  • 阿神

    阿神2017-06-23 09:13:29

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

    reply
    0
  • Cancelreply