Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

websocket-ruby

> 编程语言
Open source

Universal Ruby library to handle WebSocket protocol

464 stars0 likes3 views
WebsiteGitHub

About

Universal Ruby library to handle WebSocket protocol

WebSocket Ruby

Universal Ruby library to handle WebSocket protocol. It focuses on providing abstraction layer over WebSocket API instead of providing server or client functionality. Autobahn tests: server, client

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

  • hixie-75
  • hixie-76
  • all hybi drafts (00-13)
  • RFC 6455

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

…

Parsing and constructing frames

ruby
# Prepare frame for sending
frame = WebSocket::Frame::Outgoing::Server.new(version: @handshake.version, data: "Hello", type: :text)
frame.to_s # "\x81\x05\x48\x65\x6c\x6c\x6f"

# Parse incoming frames
frame = WebSocket::Frame::Incoming::Server.new(version: @handshake.version)
frame << "\x81\x05\x48\x65\x6c\x6c\x6f\x81\x06\x77\x6f\x72\x6c\x64\x21"
frame.next # "Hello"
frame.next # "world!""

Examples & Projects using WebSocket-Ruby

  • WebSocket-EventMachine-Client - client based on EventMachine
  • WebSocket-EventMachine-Server - server based on EventMachine (drop-in replacement for EM-WebSocket)
  • Selenium-WebDriver - tool for writing automated tests of websites
  • Rubame - websocket game server

Native extension

WebSocket gem is written in pure Ruby, without any dependencies or native extensions and still is one of the fastest implementations of WebSocket API. However, if you want to increase it's speed even further, I created additional gem with dedicated native extensions for both C and Java. Those extensions provide 20-30% increase in speed(more accurate comparison can be found in autobahn test results)

In order to use native extension just install websocket-native gem or add it to Gemfile - WebSocket will automatically detect and load it.

Support

If you like my work then consider supporting me:

License

(The MIT License)

Copyright © 2012 Bernard Potocki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 3 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言