Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
EventMachine client library for WebSockets
Ruby
branch: master

Merge pull request #5 from movitto/expose-websocket-api

Expose websocket protocol_version and origin attributes
latest commit e8389ee27a
@mwylde authored
Failed to load latest commit information.
lib
.document
.gitignore Ignore Gemfile.lock
.rspec
Gemfile
LICENSE.txt
README.md
Rakefile
VERSION
em-websocket-client.gemspec Regenerate gemspec for version 0.1.2

README.md

em-websocket-client

This gem implements a simple websocket client inside EventMachine. This might be useful for testing web socket servers or consuming WebSocket APIs. In particular it supports the RFC6455 version of the protocol, which is also implemented in Chrome and Safari. At this time, the wss (WebSocket over SSL) protocol is not supported.

Using the library is simple:

require 'em-websocket-client'

EM.run do
  conn = EventMachine::WebSocketClient.connect("ws://echo.websocket.org/")

  conn.callback do
    conn.send_msg "Hello!"
    conn.send_msg "done"
  end

  conn.errback do |e|
    puts "Got error: #{e}"
  end

  conn.stream do |msg|
    puts "<#{msg}>"
    if msg.data == "done"
      conn.close_connection
    end
  end

  conn.disconnect do
    puts "gone"
    EM::stop_event_loop
  end
end

# prints out:
# <Hello!>
# <done>
# gone
Something went wrong with that request. Please try again.