A summary of data about the Ruby ecosystem.

https://github.com/igrigorik/em-websocket

EventMachine based WebSocket server
https://github.com/igrigorik/em-websocket

Keywords from Contributors

activerecord activejob mvc rack sinatra rubygems feature-flag

Last synced: about 4 hours ago
JSON representation

Repository metadata

EventMachine based WebSocket server

README.md

EM-WebSocket

Gem Version
Analytics

EventMachine based, async, Ruby WebSocket server. Take a look at examples directory, or check out the blog post: Ruby & Websockets: TCP for the Web.

Simple server example

require 'em-websocket'

EM.run {
  EM::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws|
    ws.onopen { |handshake|
      puts "WebSocket connection open"

      # Access properties on the EM::WebSocket::Handshake object, e.g.
      # path, query_string, origin, headers

      # Publish message to the client
      ws.send "Hello Client, you connected to #{handshake.path}"
    }

    ws.onclose { puts "Connection closed" }

    ws.onmessage { |msg|
      puts "Recieved message: #{msg}"
      ws.send "Pong: #{msg}"
    }
  end
}

Protocols supported, and protocol specific functionality

Supports all WebSocket protocols in use in the wild (and a few that are not): drafts 75, 76, 1-17, rfc.

While some of the changes between protocols are unimportant from the point of view of application developers, a few drafts did introduce new functionality. It's possible to easily test for this functionality by using

Ping & pong supported

Call ws.pingable? to check whether ping & pong is supported by the protocol in use.

It's possible to send a ping frame (ws.ping(body = '')), which the client must respond to with a pong, or the server can send an unsolicited pong frame (ws.pong(body = '')) which the client should not respond to. These methods can be used regardless of protocol version; they return true if the protocol supports ping&pong or false otherwise.

When receiving a ping, the server will automatically respond with a pong as the spec requires (so you should not write an onping handler that replies with a pong), however it is possible to bind to ping & pong events if desired by using the onping and onpong methods.

Healthchecks

It's possible to send a regular HTTP GET request to the /healthcheck endpoint and receive a 200 response from the server.

Close codes and reasons

A WebSocket connection can be closed cleanly, regardless of protocol, by calling ws.close(code = nil, body = nil).

Early protocols just close the TCP connection, draft 3 introduced a close handshake, and draft 6 added close codes and reasons to the close handshake. Call ws.supports_close_codes? to check whether close codes are supported (i.e. the protocol version is 6 or above).

The onclose callback is passed a hash which may contain following keys (depending on the protocol version):

  • was_clean: boolean indicating whether the connection was closed via the close handshake.
  • code: the close code. There are two special close codes which the server may set (as defined in the WebSocket spec):
    • 1005: no code was supplied
    • 1006: abnormal closure (the same as was_clean: false)
  • reason: the close reason

Acceptable close codes are defined in the WebSocket rfc (http://tools.ietf.org/html/rfc6455#section-7.4). The following codes can be supplies when calling ws.close(code):

  • 1000: a generic normal close
  • range 3xxx: reserved for libraries, frameworks, and applications (and can be registered with IANA)
  • range 4xxx: for private use

If unsure use a code in the 4xxx range. em-websocket may also close a connection with one of the following close codes:

  • 1002: WebSocket protocol error.
  • 1009: Message too big to process. By default em-websocket will accept frames up to 10MB in size. If a frame is larger than this the connection will be closed without reading the frame data. The limit can be overriden globally (EM::WebSocket.max_frame_size = bytes) or on a specific connection (ws.max_frame_size = bytes).

Secure server

It is possible to accept secure wss:// connections by passing :secure => true when opening the connection. Pass a :tls_options hash containing keys as described in http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine/Connection:start_tls

Warning: Safari 5 does not currently support prompting on untrusted SSL certificates therefore using a self signed certificate may leave you scratching your head.

EM::WebSocket.start({
  :host => "0.0.0.0",
  :port => 443,
  :secure => true,
  :tls_options => {
    :private_key_file => "/private/key",
    :cert_chain_file => "/ssl/certificate"
  }
}) do |ws|
  # ...
end

It's possible to check whether an incoming connection is secure by reading handshake.secure? in the onopen callback.

Running behind an SSL Proxy/Terminator, like Stunnel

The :secure_proxy => true option makes it possible to use em-websocket behind a secure SSL proxy/terminator like Stunnel which does the actual encryption & decryption.

Note that this option is only required to support drafts 75 & 76 correctly (e.g. Safari 5.1.x & earlier, and Safari on iOS 5.x & earlier).

EM::WebSocket.start({
  :host => "0.0.0.0",
  :port => 8080,
  :secure_proxy => true
}) do |ws|
  # ...
end

Handling errors

There are two kinds of errors that need to be handled -- WebSocket protocol errors and errors in application code.

WebSocket protocol errors (for example invalid data in the handshake or invalid message frames) raise errors which descend from EM::WebSocket::WebSocketError. Such errors are rescued internally and the WebSocket connection will be closed immediately or an error code sent to the browser in accordance to the WebSocket specification. It is possible to be notified in application code of such errors by including an onerror callback.

ws.onerror { |error|
  if error.kind_of?(EM::WebSocket::WebSocketError)
    # ...
  end
}

Application errors are treated differently. If no onerror callback has been defined these errors will propagate to the EventMachine reactor, typically causing your program to terminate. If you wish to handle exceptions, simply supply an onerror callback and check for exceptions which are not descendant from EM::WebSocket::WebSocketError.

It is also possible to log all errors when developing by including the :debug => true option when initialising the WebSocket server.

Emulating WebSockets in older browsers

It is possible to emulate WebSockets in older browsers using flash emulation. For example take a look at the web-socket-js project.

Using flash emulation does require some minimal support from em-websocket which is enabled by default. If flash connects to the WebSocket port and requests a policy file (which it will do if it fails to receive a policy file on port 843 after a timeout), em-websocket will return one. Also see https://github.com/igrigorik/em-websocket/issues/61 for an example policy file server which you can run on port 843.

Examples & Projects using em-websocket

  • Pusher - Realtime Messaging Service
  • Livereload - LiveReload applies CSS/JS changes to Safari or Chrome w/o reloading
  • Twitter AMQP WebSocket Example
  • examples/multicast.rb - broadcast all ruby tweets to all subscribers
  • examples/echo.rb - server <> client exchange via a websocket

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 3 days ago

Total Commits: 314
Total Committers: 37
Avg Commits per committer: 8.486
Development Distribution Score (DDS): 0.369

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Martyn Loughran me@m****m 198
Ilya Grigorik i****a@i****m 40
Glenn Rempe g****n@r****s 11
Hiroshi Ichikawa g****e@g****m 9
Makoto Inoue m****o@n****k 7
Bernard Potocki b****i@i****g 6
richo r****o@p****t 3
Jonathan Hoskin j****n@v****m 3
Bernard Potocki b****i@g****m 2
Bernard Potocki b****i@i****g 2
Christian Larsen c****l@m****m 2
JamesVorder j****r@g****m 2
Jason Willems j****n@w****a 2
Micheil Smith m****l@b****m 2
Steve Agalloco s****o@g****m 2
zimbatm z****m@z****m 2
kyubuns jp@e****x 1
Ben Koski b****i@n****m 1
dan sinclair d****2@e****m 1
Scott Tadman g****b@t****a 1
Pavel Forkert f****r@g****m 1
Paulo Fagiani p****i@g****m 1
Patricio Mac Adden p****n@g****m 1
Nikita Vasilyev me@e****u 1
Mo Morsi m****i@r****m 1
Matt Colyer m****t@c****e 1
Matt Aimonetti m****i@g****m 1
Markus Fenske i****e@g****t 1
Jim Fisher j****r@g****m 1
Jan Lelis m****l@j****e 1
and 7 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 3 months ago

Total issues: 66
Total pull requests: 36
Average time to close issues: 7 months
Average time to close pull requests: 4 months
Total issue authors: 61
Total pull request authors: 32
Average comments per issue: 2.86
Average comments per pull request: 2.83
Merged pull request: 19
Bot issues: 0
Bot pull requests: 0

Past year issues: 1
Past year pull requests: 2
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 1
Past year pull request authors: 1
Past year average comments per issue: 0.0
Past year average comments per pull request: 0.0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/igrigorik/em-websocket

Top Issue Authors

  • mloughran (4)
  • SamSaffron (2)
  • sbrun (2)
  • shokai (1)
  • chrisallick (1)
  • lilijreey (1)
  • cybercent (1)
  • famince (1)
  • NicholasMata (1)
  • iguha0 (1)
  • cmoulliard (1)
  • anand-zz (1)
  • nealAR (1)
  • taf2 (1)
  • andrewhavens (1)

Top Pull Request Authors

  • taketo1113 (4)
  • jonathanhoskin (2)
  • richo (2)
  • stve (2)
  • bkoski (1)
  • fagiani (1)
  • at1as (1)
  • vongruenigen (1)
  • KellyMahan (1)
  • dj2 (1)
  • ThisIsMissEm (1)
  • ghost (1)
  • deivid-rodriguez (1)
  • gimite (1)
  • shokai (1)

Top Issue Labels

  • feature (4)

Top Pull Request Labels


Package metadata

gem.coop: em-websocket

EventMachine based WebSocket server

  • Homepage: http://github.com/igrigorik/em-websocket
  • Documentation: http://www.rubydoc.info/gems/em-websocket/
  • Licenses: MIT
  • Latest release: 0.5.3 (published over 4 years ago)
  • Last Synced: 2026-03-02T06:02:58.406Z (1 day ago)
  • Versions: 23
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 55,495,143 Total
  • Docker Downloads: 279,856,195
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.221%
    • Docker downloads count: 0.403%
    • Downloads: 0.48%
  • Maintainers (2)
rubygems.org: em-websocket

EventMachine based WebSocket server

  • Homepage: http://github.com/igrigorik/em-websocket
  • Documentation: http://www.rubydoc.info/gems/em-websocket/
  • Licenses: MIT
  • Latest release: 0.5.3 (published over 4 years ago)
  • Last Synced: 2026-03-02T03:32:09.104Z (1 day ago)
  • Versions: 23
  • Dependent Packages: 152
  • Dependent Repositories: 411,081
  • Downloads: 55,493,236 Total
  • Docker Downloads: 279,856,195
  • Rankings:
    • Dependent repos count: 0.042%
    • Dependent packages count: 0.226%
    • Downloads: 0.448%
    • Docker downloads count: 0.584%
    • Average: 0.744%
    • Stargazers count: 1.237%
    • Forks count: 1.925%
  • Maintainers (2)
alpine-v3.18: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r2 (published almost 3 years ago)
  • Last Synced: 2026-02-14T15:48:19.254Z (17 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 3.226%
    • Stargazers count: 5.885%
    • Forks count: 7.017%
  • Maintainers (1)
proxy.golang.org: github.com/igrigorik/em-websocket

alpine-edge: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r4 (published 10 months ago)
  • Last Synced: 2026-02-23T14:00:40.092Z (8 days ago)
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Stargazers count: 6.011%
    • Average: 7.127%
    • Forks count: 7.855%
    • Dependent packages count: 14.641%
  • Maintainers (1)
alpine-v3.15: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r0 (published over 4 years ago)
  • Last Synced: 2026-02-12T12:27:07.443Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Stargazers count: 4.295%
    • Forks count: 5.184%
    • Average: 8.766%
    • Dependent packages count: 25.585%
  • Maintainers (1)
alpine-v3.16: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r1 (published almost 4 years ago)
  • Last Synced: 2026-02-19T11:10:26.468Z (12 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Stargazers count: 4.59%
    • Forks count: 5.283%
    • Average: 9.296%
    • Dependent packages count: 27.311%
  • Maintainers (1)
alpine-v3.17: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r1 (published almost 4 years ago)
  • Last Synced: 2026-02-03T04:49:55.624Z (29 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Stargazers count: 5.917%
    • Forks count: 6.635%
    • Average: 9.951%
    • Dependent packages count: 27.254%
  • Maintainers (1)
conda-forge.org: rb-em-websocket

  • Homepage: https://rubygems.org/gems/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.1 (published over 6 years ago)
  • Last Synced: 2026-02-02T21:35:01.289Z (29 days ago)
  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Rankings:
    • Stargazers count: 9.686%
    • Forks count: 12.835%
    • Average: 18.958%
    • Dependent repos count: 24.338%
    • Dependent packages count: 28.974%
ubuntu-23.04: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 20 days ago)
  • Last Synced: 2026-02-11T06:38:35.192Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 22 days ago)
  • Last Synced: 2026-02-09T16:28:05.851Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Documentation: https://packages.debian.org/bullseye/ruby-em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 21 days ago)
  • Last Synced: 2026-02-13T08:19:56.945Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T07:12:53.204Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T18:18:43.363Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
alpine-v3.19: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r2 (published almost 3 years ago)
  • Last Synced: 2026-02-18T08:10:12.642Z (13 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
  • Maintainers (1)
alpine-v3.20: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r3 (published about 2 years ago)
  • Last Synced: 2026-02-20T15:09:01.396Z (11 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
  • Maintainers (1)
debian-12: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Documentation: https://packages.debian.org/bookworm/ruby-em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 19 days ago)
  • Last Synced: 2026-02-12T23:28:40.840Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 19 days ago)
  • Last Synced: 2026-02-13T01:03:02.516Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T13:16:10.770Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
alpine-v3.23: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r4 (published 10 months ago)
  • Last Synced: 2026-02-03T15:55:28.109Z (28 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-13: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Documentation: https://packages.debian.org/trixie/ruby-em-websocket
  • Licenses:
  • Latest release: 0.5.3-1 (published 19 days ago)
  • Last Synced: 2026-02-13T13:15:01.564Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
alpine-v3.22: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r4 (published 10 months ago)
  • Last Synced: 2026-02-03T04:50:18.243Z (29 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
  • Maintainers (1)
alpine-v3.21: ruby-em-websocket

EventMachine based WebSocket server

  • Homepage: https://github.com/igrigorik/em-websocket
  • Licenses: MIT
  • Latest release: 0.5.3-r3 (published about 2 years ago)
  • Last Synced: 2026-02-03T04:49:49.185Z (29 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
  • Maintainers (1)
debian-10: ruby-em-websocket

  • Homepage: https://github.com/igrigorik/em-websocket
  • Documentation: https://packages.debian.org/buster/ruby-em-websocket
  • Licenses:
  • Latest release: 0.5.1-2 (published 20 days ago)
  • Last Synced: 2026-02-13T04:20:52.523Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

Gemfile rubygems
  • em-http-request ~> 1.1.1
  • em-spec ~> 0.2.6
  • em-websocket-client >= 0
  • rake >= 0
  • rspec ~> 3.5.0
em-websocket.gemspec rubygems
  • eventmachine >= 0.12.9
  • http_parser.rb ~> 0

Score: 31.38311896407336