No commit activity in last 3 years
No release in over 3 years
A WebSocket client implementation for EventMachine
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.0
~> 1.8.0
~> 2.3.0
~> 0.6.0

Runtime

 Project Readme

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