Results 1 to 2 of 2

Thread: [RESOLVED] UDP Connection - How To?

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    York
    Posts
    197

    [RESOLVED] UDP Connection - How To?

    Hi:

    After reading php.net - i came up with this code
    Unfortunately I get some errors.

    PHP Code:
    <?php
        
    echo "Quake 3 server test<H5>";
        
        
    // Quake 3 server
        
    $host "213.249.227.8";
        
    $port 27960;
        
        
    // Create a UDP Socket

        
    $socket socket_create (AF_INETSOCK_DGRAMSOL_UDP);
        
        
    // Create the Q3 getstatus request
        
    $q3request str_repeat(chr(0xFF),4)."getstatus".chr(0x0A);
        
        
    // Send the UDP Packet
        
    socket_sendto($socket$q3requeststrlen($q3request), 0x100$host$port);
        
        
    $buffer '';
      
    $port '';
      
    $ret '';
        do
       {
         
    // $buffer and $port both come back with information for the ack
         // 516 = 4 bytes for the header + 512 bytes of data
         
    socket_recvfrom($socket$buffer5160$host$port);

         
    // add the block number from the data packet to the ack packet
         
    $packet chr(0) . chr(4) . substr($buffer22);
         
    // send ack
         
    socket_sendto($socket$packetstrlen($packet), 0$host$port);

         
    // append the data to the return variable
         // for large files this function should take a file handle as an arg
         
    $ret .= substr($buffer4);
       }
       while(
    strlen($buffer) == 516);  // the first non-full packet is the last.
        
        
    echo $ret
        
    ?>
    And here are the associated output and errors

    Code:
    Quake 3 server test
    PHP Warning: socket_sendto() [function.socket-sendto]: unable to write to socket [0]: The attempted operation is not supported for the type of object referenced. in F:\Dev-php2\Projects\Q3ServerTest1.php on line 15 
    PHP Warning: socket_recvfrom() [function.socket-recvfrom]: unable to recvfrom [0]: The operation completed successfully. in F:\Dev-php2\Projects\Q3ServerTest1.php on line 24 
    PHP Warning: socket_sendto() expects parameter 6 to be long, string given in F:\Dev-php2\Projects\Q3ServerTest1.php on line 29
    Hope someone can help - btw - this is my second php app lol

    Cheers.
    Last edited by Raedwulf; Mar 8th, 2006 at 06:48 AM. Reason: Resolved

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    York
    Posts
    197

    Re: UDP Connection - How To?

    I resolved it
    Rather than
    PHP Code:
    socket_sendto($socket$q3requeststrlen($q3request), 0x100$host$port); 
    This works:
    PHP Code:
    socket_sendto($socket$q3requeststrlen($q3request), 0x0$host$port); 
    Cheers....hope this helps someone

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width