• Stars
    star
    376
  • Rank 113,110 (Top 3 %)
  • Language
    Ruby
  • Created about 15 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTML5 Web Socket server/client implementation in Ruby
HTML5 Web Socket server/client implementation in Ruby.

For server, em-websocket ( https://github.com/igrigorik/em-websocket ) may be a better choice, especially if you want to use EventMachine.


* How to run sample

- Run sample Web Socket server (echo server) with:
  $ ruby samples/echo_server.rb localhost 10081

- Run sample Web Socket client and type something:
  $ ruby samples/stdio_client.rb ws://localhost:10081
  Ready
  hoge
  Sent: "hoge"
  Received: "hoge"


* Usage example

Server:

  # Runs the server at port 10081. It allows connections whose origin is example.com.
  server = WebSocketServer.new(:port => 10081, :accepted_domains => ["example.com"])
  server.run() do |ws|
    # The block is called for each connection.
    # Checks requested path.
    if ws.path == "/"
      # Call ws.handshake() without argument first.
      ws.handshake()
      # Receives one message from the client as String.
      while data = ws.receive()
        puts(data)
        # Sends the message to the client.
        ws.send(data)
      end
    else
      # You can call ws.handshake() with argument to return error status.
      ws.handshake("404 Not Found")
    end
  end

Client:

  # Connects to Web Socket server at host example.com port 10081.
  client = WebSocket.new("ws://example.com:10081/")
  # Sends a message to the server.
  client.send("Hello")
  # Receives a message from the server.
  data = client.receive()
  puts(data)


* Supported WebSocket protocol versions

WebSocketServer class (server) accepts version hixie-75, hixie-76, hybi-07, hybi-10.
WebSocket class (client) speaks version hixie-76.


* Tips: JavaScript client implementation

Google Chrome Dev Channel natively supports Web Socket. For other browsers, you can use an implementation using Flash:
http://github.com/gimite/web-socket-js/tree/master


* WebSocket protocol versions

The server supports the protocol defined in RFC 6455, draft versions hixie-75 and hixie-76.

The client speaks draft version hixie-76.


* License

New BSD License.

More Repositories

1

web-socket-js

HTML5 Web Socket implementation powered by Flash
JavaScript
2,735
star
2

google-drive-ruby

A Ruby library to read/write files/spreadsheets in Google Drive/Docs.
Ruby
1,744
star
3

google-spreadsheet-ruby

Ruby library to read/write Google Spreadsheet
Ruby
302
star
4

moji

Ruby library for character type classification/conversion for Japanese
Ruby
86
star
5

android-native-exe-demo

Demo app to run native executable on Android app
Java
56
star
6

tweet-search-stream

Real time Twitter search using Twitter Streaming API, hosted at http://tweet-search-stream.gimite.net/
JavaScript
49
star
7

mjai

Game server for Japanese Mahjong AI.
Ruby
47
star
8

mjai-manue

Japanese Mahjong AI.
CoffeeScript
34
star
9

hrwt

Ruby VM on JavaScript (based on HotRuby) + RPC.
Ruby
30
star
10

web-irc-util

Web-based IRC client (based on QuickIRC2) + IRC log viewer used in irc.gimite.net.
Ruby
11
star
11

tx-ruby

Ruby 1.8/1.9 binding of Tx, a library for a compact trie data structure.
Ruby
10
star
12

android-jatts

Japanese TTS for Android, using Galatea Talk in server side
Java
8
star
13

kanjy-wave

Google Wave Robot to perform Japanese IME using Social IME API.
Python
6
star
14

mail-speaks

Android app to notify new emails with voice
Java
5
star
15

em-fiber-utils

Provides concurrent version of each() which works in EventMachine + Fiber environment.
Ruby
3
star
16

gimite-tools

Unix commands for my personal use.
Ruby
2
star
17

touchauth_demo

JavaScript
2
star
18

gae-rest-uploader

An uploader which runs on Google AppEngine with a simple REST API.
Python
2
star
19

MjaiClients

Mahjong AI clients for Mjai
Java
2
star
20

gimite.github.io

CSS
1
star
21

gimite-test

Gimite's testing repository.
HTML
1
star
22

kantan-kensaku

Automatically exported from code.google.com/p/kantan-kensaku
Java
1
star