I have also tried sending udp packets. I found that my packets were not being written for whatever reason.
PHP Code:
<?php
$fp = fsockopen("udp://".$_GET['IP'], $_GET['PORT'], $errno, $errstr);
if (!$fp){
echo "ERROR: $errno - $errstr<br />\n";
}
else{
echo "IP: ".$_GET['IP']."<br />";
echo "Port: ".$_GET['PORT']."<br />";
echo "Data to Write: \\".$_GET['d']."\\<br />";
echo "Bytes written to socket: ".fwrite($fp, "\\".$_GET['d']."\\")."<br />";
stream_set_timeout($fp, 2);
$res = fread($fp, 2000);
$info = stream_get_meta_data($fp);
fclose($fp);
if ($info['timed_out']){
echo 'Connection timed out!';
}
else{
echo "Returned data: ".$res;
}
}
?>
yourFileNameHere.php?IP=theIPgoesHere&PORT=thePort Here&d=theDataToSend
fwrite returns the amount of bytes written. Oh, and the above script is sending data with a \ on either side of the data. That is app specific, just remove those if not applicable.