-
Mar 7th, 2006, 02:46 PM
#1
Thread Starter
Addicted Member
[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_INET, SOCK_DGRAM, SOL_UDP);
// Create the Q3 getstatus request
$q3request = str_repeat(chr(0xFF),4)."getstatus".chr(0x0A);
// Send the UDP Packet
socket_sendto($socket, $q3request, strlen($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, $buffer, 516, 0, $host, $port);
// add the block number from the data packet to the ack packet
$packet = chr(0) . chr(4) . substr($buffer, 2, 2);
// send ack
socket_sendto($socket, $packet, strlen($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($buffer, 4);
}
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
-
Mar 8th, 2006, 06:48 AM
#2
Thread Starter
Addicted Member
Re: UDP Connection - How To?
I resolved it
Rather than
PHP Code:
socket_sendto($socket, $q3request, strlen($q3request), 0x100, $host, $port);
This works:
PHP Code:
socket_sendto($socket, $q3request, strlen($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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|