I am a complete beginner when it comes to udp.. I understand that it differs from TCP in that you don't get a confirmation the packet was delivered.. but that is about it.

Basicly whatn I need to do is have php connect to my ip address (10.0.0.4) and send the message '3422' to the ip address.

do I use socket_send?

    screative wrote:

    I am a complete beginner when it comes to udp.. I understand that it differs from TCP in that you don't get a confirmation the packet was delivered.. but that is about it.

    Wrong. TCP doesn't give you a confirmation either, but it will transparently retry if an error occurs, up to some timeout.

    TCP however, does not work in packets, it works in streams; that's to say, lumps of data you send may be joined together or split up as necessary by the underlying implementation.

    UDP does not do this; it preserves message boundaries.

    Basicly whatn I need to do is have php connect to my ip address (10.0.0.4) and send the message '3422' to the ip address.

    UDP has no notion of what a "connection" is, you simply send messages and hope they get there (unless you protocol has some built-in acknowledgement mechanism, in which case you must implement it correctly).

    do I use socket_send?

    Maybe.

    The easiest way and most modern way in PHP is using fsockopen - this will always be available and will support UDP if the OS supports it (which is basically always):

    
    $sock = fsockopen("udp://wherever", $port_number, $errno, $errstr);
    
    $res = fwrite($sock, $some_binary_data); // Sends a UDP message
    

    I consider the socket_ functions deprecated.

    Mark

      Modified from http://us.php.net/manual/en/ref.curl.php#74814

      <?php
      
      $data = '3422'
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'http://10.0.0.4');
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      curl_exec($ch);
      
      ?>

      That will post 3422 to 10.0.0.4 on port 80

        Write a Reply...