phpsocketstcpipascii

Php send 65 Ascii char to socket


Im trying to send a 65 ascii char to a device Im reading from via php sockets. I need to reply to confirm the info has been received.

I have tried the following with no joy:

$ascii = ord("A"); // 65    
socket_write($spawn, $ascii, strlen ($ascii)) or die("Could not write output\n"); 

is this correct?


Solution

  • You're sending the string "65", not a single byte with that value. You can do:

    socket_write($spawn, chr(65), 1) or die("Could not write output\n");