Does anyone know how to write binary data in a PHP socket?

I have tried using standard file functions but it doesn't work. This is my code:

<?php
	$fp = fsockopen("127.0.0.1", 15000, &$errno, &$errstr, 30);

if(!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
$num = 65;
fwrite($fp,$num,4);

fclose($fp);
}
?

    It's certainly possible, but you'll probably want to [man]pack[/man] the data into the necessary format; the normal type-conversion rules would convert 65 into 0x36 0x35.

      Thank you very much. Your answer solved my problem.

        Write a Reply...