Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/imanel/websocket-ruby

Universal Ruby library to handle WebSocket protocol
https://github.com/imanel/websocket-ruby

Last synced: 2 months ago
JSON representation

Universal Ruby library to handle WebSocket protocol

Awesome Lists containing this project

README

        

# WebSocket Ruby

Universal Ruby library to handle WebSocket protocol. It focuses on providing abstraction layer over [WebSocket API](http://dev.w3.org/html5/websockets/) instead of providing server or client functionality.

[![Gem Version](https://badge.fury.io/rb/websocket.svg)](http://badge.fury.io/rb/websocket)
[![Gem Downloads](https://img.shields.io/gem/dt/websocket.svg?maxAge=2592000)](https://rubygems.org/gems/websocket)
[![Code Climate](https://codeclimate.com/github/imanel/websocket-ruby.svg)](https://codeclimate.com/github/imanel/websocket-ruby)

**Autobahn tests:** [server](http://imanel.github.com/websocket-ruby/autobahn/server/), [client](http://imanel.github.com/websocket-ruby/autobahn/client/)

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

- [hixie-75](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75)
- [hixie-76](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76)
- [all hybi drafts (00-13)](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17)
- [RFC 6455](http://datatracker.ietf.org/doc/rfc6455/)

## 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

``` ruby
@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 << <