Greetings all,
i am trying to listen on a udp port and save everything recieved into a text file using php.
so far i have this:
#!/usr/local/bin/php –q
<?php
// Server IP address
$address = "192.168.1.6";
// Port to listen
$port = 3658;
$mysock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($mysock,$address, $port) or die('Could not bind to address');
socket_listen($mysock, 5);
$client = socket_accept($mysock);
// read 1024 bytes from client
$input = socket_read($client, 1024);
// write received data to the file
writeToFile('abc.txt', $input);
socket_close($client);
socket_close($mysock);
?>
<?
/**
* write string to file
*/
function writeToFile($strFilename, $strText)
{
if($fp = @fopen($strFilename,"w "))
{
$contents = fwrite($fp, $strText);
fclose($fp);
return true;
}else{
return false;
}
}
?>
and it doesnt look great because i have all these errors:
Warning: socket_listen() [function.socket-listen]: unable to listen on socket [0]: The attempted operation is not supported for the type of object referenced. in C:\xampp\htdocs\new.php on line 14
Warning: socket_accept() [function.socket-accept]: unable to accept incoming connection [0]: The attempted operation is not supported for the type of object referenced. in C:\xampp\htdocs\new.php on line 15
Warning: socket_read() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\new.php on line 18
Warning: socket_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\new.php on line 23
could some one please enlighten me as to what i am doing wronge? it would be most appreciated.
Astro