> as soon as i stop reading from the socket the connection is reset... > data=(sock.gets.unpack("H*")) > if data.to_s.include?("f7010800") == true > ping=data.to_s.index("f7010800") > sock.print(["#{data.to_s[ping..ping+15]}"].pack("H*")) That's not even a complete code snippet - where is the 'end' which balances the 'if'? Anyway, when reading from a socket, you can use: sock.gets -- reads up to a newline (0x0a) character sock.getc -- reads one byte (note: integer in 1.8, string in 1.9) sock.read(n) -- reads exactly n bytes (as a string) sock.readpartial(n) -- reads at least 1 and up to n bytes, depending on what's available in the buffer at that time if select([sock],nil,nil,10) ... end -- checks whether at least 1 byte is available to read, or times out after 10 seconds Almost certainly I'd say you want sock.read(n), not sock.gets, because it doesn't look like the binary data you're reading ends with a newline character. Also, note that you can embed hex bytes in strings - this might be easier than pack, at least for short strings. sock.print "\xf7\x1e\x2d\x00\xc5\x0d..." HTH, Brian. -- Posted via http://www.ruby-forum.com/.