omegad Posted March 5, 2007 Share Posted March 5, 2007 I am trying to be able to send data one byte at a time over a TCP socket connection. I want to be able to send hex directly and not use ascii. Right now when I send 0xFF it comes out on the other end as the decimal ascii value not the hex value like it would if i sent a byte in c++. I know the php does not handle bytes but, is there a way to force this? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 I don't understand your question. There is no distinction in either php or c++ between a hex value and an ascii value. What happens when you display the decimal ascii value as hex? Quote Link to comment Share on other sites More sharing options...
omegad Posted March 5, 2007 Author Share Posted March 5, 2007 Sorry I guess what i really want to do is send a byte of data from a php socket like I could in C++. The problem is that I need to interface with a binary protocol not an ascii one. What I am trying to do is send data to a networked micro controller which is only 16 bit. Within php the value I send goes through as ascii. In C++ if I have a byte variable and I set it to 0x15 when it gets to the client it comes out as 0x15. In php, however if I set a variable to 0x15 and send it to the client it comes out as ascii 15 a.k.a 0x31 0x35 two bytes not one. I could send single chars since each ascii char is a byte, ex A = 0x41, B = 0x42, etc. However this only gives me a range of 0x21 through 0x7E which does not work for what I need. So I was wondering if there were a way to send straight hex not ascii? Quote Link to comment Share on other sites More sharing options...
omegad Posted March 5, 2007 Author Share Posted March 5, 2007 Ok so I figured it out... if I use: socket_write($socket, chr($in), strlen(chr($in))); Where $in is the value I want to send, php will convert it to a single byte. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.