From: Rick DeNatale Date: 2007-05-25T07:03:03+09:00 Subject: Re: sending data, no strings via socket On 5/24/07, Javier None wrote: > I'm trying to send data like > > typedef struct{ > u_int32_t type; > u_int8_t len; > u_int8_t * buf; > } > > over a tcp socket using ruby. > > Anything I push over the socket comes out the other end as a string.. > > in Ruby.. > > data = 10 > socket = TCPSocket.new(home,port) > socket.write(data) > > on the other end I get > receieved byte dump > 0000: 31 30 10 > > which is the ascii for 10. How can I tell Ruby to send the 0x10? > even if I write > data = 0x10 > on the other side I get: > 0000: 31 36 16 > Which again, is the ascii getting send, not the data. > thanks for any help. Well, write takes a string representing the datastream to be written so you need a string with the binary data. if you are trying to write a single byte then data = 10.chr You might also want to look at Array#pack -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ IPMS/USA Region 12 Coordinator http://ipmsr12.denhaven2.com/ Visit the Project Mercury Wiki Site http://www.mercuryspacecraft.com/