send non-ascii over socket_write
Posted: Sun Oct 04, 2009 6:32 pm
I need to send a null terminated string over a socket, such that i get an ascii string followed by 0x00.
i've only been able to send valid ascii characters using socket_write.
i've tried:
a) tell socket write to send an extra byte by: socket_write($socket, $string, strlen($string)+1) but that doesnt send the 0x00 i need as well.
b) socket_write fails in this case
c) appends a '0' character to my msg
i could really use some help. surely people send non-printable characters over a socket all the time.
i've only been able to send valid ascii characters using socket_write.
i've tried:
a) tell socket write to send an extra byte by: socket_write($socket, $string, strlen($string)+1) but that doesnt send the 0x00 i need as well.
b) socket_write fails in this case
Code: Select all
$xml=str_split($xml);
$xml[]=0x00;
if (!socket_write($user->socket, $xml)) logger("Failed to write to socket ".socket_last_error());
Code: Select all
$xml[strlen($xml)]=0x00;