afro360
afro360

Reputation: 620

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?

Upvotes: 0

Views: 734

Answers (2)

Dushyant Rajpurohit
Dushyant Rajpurohit

Reputation: 1

To send the character 'A' to the device, you should send it as a string rather than its ASCII value. Here's how you can do it:

$character = "A"; // The character you want to send socket_write($spawn, $character, strlen($character)) or die("Could not write output\n");

Upvotes: 0

Barmar
Barmar

Reputation: 780974

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");

Upvotes: 1

Related Questions