WebSocket Ruby

Universal Ruby library to handle WebSocket protocol. It focuses on providing abstraction layer over WebSocket API instead of providing server or client functionality.

Gem Version
Gem Downloads
Code Climate

Autobahn tests: server, client

Currently WebSocket Ruby supports all existing drafts of WebSocket, which include:

Installation

WebSocket Ruby has no external dependencies, so it can be installed from source or directly from rubygems:

gem install "websocket"

or via Gemfile:

gem "websocket"

Server handshake

@handshake = WebSocket::Handshake::Server.new

# Parse client request
@handshake << < 'SESSIONID=1234' })

# Create request
@handshake.to_s # GET /demo HTTP/1.1
                # Upgrade: websocket
                # Connection: Upgrade
                # Host: example.com
                # Cookie: SESSIONID=1234
                # Origin: http://example.com
                # Sec-WebSocket-Version: 13
                # Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

# Parse server response
@handshake << <