From: Robert Klemme Date: 2011-08-20T17:56:54+09:00 Subject: Re: Socket not sending correctly? On Fri, Aug 19, 2011 at 6:18 PM, Chananya F. wrote: > I am implementing the WebSocket specification since it doesn't appears > that there are ANY server-side implementations that are not completely > outdated (draft 76 which _expired_ 1 year ago...). > > I managed to get the handshake, and I can receive messages from my > JavaScript client code, but I just can't get my Ruby code to send > messages correctly. > > It shouldn't be hard at all, just have to follow the protocol here > http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#section-4.2 > , except no matter what I try it doesn't work. > > I even tried the simple example they give - sending "Hello" with the > following hexadecimal numbers - 0x81, 0x5, 0x48, 0x65, 0x6C, 0x6C, 0x6F. > I do this by simply sending them in a string > > @socket.write("\x81\x05\x48\x65\x6C\x6C\x6F") > > Yet that doesn't work either, and if that doesn't work, I can't find any > reason beside Ruby failing to send the bits correctly. > > The code MUST send 0x81 and 0x05 correctly, meaning: > 10000001 00000101 > > Anyone has any ideas? Try socket.sync = true or even better use #flush. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/