https://github.com/imanel/websocket-ruby
Universal Ruby library to handle WebSocket protocol
https://github.com/imanel/websocket-ruby
Keywords from Contributors
rubygems activejob activerecord mvc rack rspec feature-flag static-code-analysis rubocop code-formatter
Last synced: about 5 hours ago
JSON representation
Repository metadata
Universal Ruby library to handle WebSocket protocol
- Host: GitHub
- URL: https://github.com/imanel/websocket-ruby
- Owner: imanel
- Created: 2010-12-05T00:50:28.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2025-06-12T15:52:18.000Z (6 months ago)
- Last Synced: 2025-11-27T19:23:49.759Z (14 days ago)
- Language: Ruby
- Homepage:
- Size: 2.79 MB
- Stars: 452
- Watchers: 13
- Forks: 44
- Open Issues: 3
- Releases: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
README.md
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:
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
@handshake = WebSocket::Handshake::Server.new
# Parse client request
@handshake << <<EOF
GET /demo HTTP/1.1\r
Upgrade: websocket\r
Connection: Upgrade\r
Host: example.com\r
Origin: http://example.com\r
Sec-WebSocket-Version: 13\r
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r
\r
EOF
# All data received?
@handshake.finished?
# No parsing errors?
@handshake.valid?
# Create response
@handshake.to_s # HTTP/1.1 101 Switching Protocols
# Upgrade: websocket
# Connection: Upgrade
# Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Client handshake
@handshake = WebSocket::Handshake::Client.new(url: 'ws://example.com', headers: { 'Cookie' => 'SESSIONID=1234' })
# Create request
@handshake.to_s # GET /demo HTTP/1.1
# Upgrade: websocket
# Connection: Upgrade
# Host: example.com
# Cookie: SESSIONID=1234
# Origin: http://example.com
# Sec-WebSocket-Version: 13
# Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
# Parse server response
@handshake << <<EOF
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r
\r
EOF
# All data received?
@handshake.finished?
# No parsing errors?
@handshake.valid?
Parsing and constructing frames
# 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.
Owner metadata
- Name: Bernard Potocki
- Login: imanel
- Email:
- Kind: user
- Description:
- Website:
- Location: Warsaw, Poland
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/36869?v=4
- Repositories: 95
- Last ynced at: 2024-04-14T07:07:58.401Z
- Profile URL: https://github.com/imanel
GitHub Events
Total
- Watch event: 6
- Pull request event: 1
- Create event: 1
Last Year
- Watch event: 6
- Pull request event: 1
- Create event: 1
Committers metadata
Last synced: 1 day ago
Total Commits: 368
Total Committers: 17
Avg Commits per committer: 21.647
Development Distribution Score (DDS): 0.092
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 | Commits | |
|---|---|---|
| Bernard Potocki | b****i@i****g | 334 |
| Piotr Zientara | 3****a@g****m | 6 |
| Nick Gauthier | n****r@g****m | 5 |
| Dávid Halász | d****z@r****m | 3 |
| Mark Bryant | M****t@s****m | 3 |
| Olle Jonsson | o****n@g****m | 3 |
| Pat Allan | p****t@f****m | 3 |
| Yusuke Endoh | m****e@r****g | 2 |
| Akira Matsuda | r****e@d****p | 1 |
| Alex Rodionov | p****e@g****m | 1 |
| Antonio Terceiro | t****o@s****g | 1 |
| Juanito Fatas | me@j****m | 1 |
| Masamitsu MURASE | m****e@g****m | 1 |
| OKURA Masafumi | m****8@g****m | 1 |
| Vít Ondruch | v****h@r****m | 1 |
| adamjonas | j****s@f****m | 1 |
| ecin | e****n@c****m | 1 |
Committer domains:
- redhat.com: 2
- copypastel.com: 1
- flatironschool.com: 1
- juanitofatas.com: 1
- softwarelivre.org: 1
- dio.jp: 1
- ruby-lang.org: 1
- freelancing-gods.com: 1
- sumo-digital.com: 1
- imanel.org: 1
Issue and Pull Request metadata
Last synced: about 1 month ago
Total issues: 22
Total pull requests: 35
Average time to close issues: 3 months
Average time to close pull requests: 7 days
Total issue authors: 19
Total pull request authors: 22
Average comments per issue: 2.45
Average comments per pull request: 2.66
Merged pull request: 32
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 2
Past year average time to close issues: N/A
Past year average time to close pull requests: 6 days
Past year issue authors: 0
Past year pull request authors: 2
Past year average comments per issue: 0
Past year average comments per pull request: 1.5
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- donpdonp (2)
- imanel (2)
- zh99998 (2)
- skateman (1)
- johnny (1)
- nateless (1)
- lukeredpath (1)
- tarcieri (1)
- gmallard (1)
- ljckennedy (1)
- andresespinosapc (1)
- BanzaiMan (1)
- Paxa (1)
- julianschuh (1)
- yfeldblum (1)
Top Pull Request Authors
- imanel (11)
- olleolleolle (3)
- skateman (2)
- amatsuda (2)
- mark-young-atg (2)
- mame (2)
- voxik (1)
- pat (1)
- ecin (1)
- mwylde (1)
- Sumo-MBryant (1)
- authorNari (1)
- JuanitoFatas (1)
- ianwdunlop (1)
- goldibex (1)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 344,513,028 total
- Total docker downloads: 1,607,357,556
- Total dependent packages: 75 (may contain duplicates)
- Total dependent repositories: 77,101 (may contain duplicates)
- Total versions: 73
- Total maintainers: 1
gem.coop: websocket
Universal Ruby library to handle WebSocket protocol
- Homepage: http://github.com/imanel/websocket-ruby
- Documentation: http://www.rubydoc.info/gems/websocket/
- Licenses: MIT
- Latest release: 1.2.11 (published over 1 year ago)
- Last Synced: 2025-12-11T01:01:35.724Z (1 day ago)
- Versions: 24
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 172,223,349 Total
- Docker Downloads: 803,678,778
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.066%
- Docker downloads count: 0.117%
- Downloads: 0.148%
- Maintainers (1)
rubygems.org: websocket
Universal Ruby library to handle WebSocket protocol
- Homepage: http://github.com/imanel/websocket-ruby
- Documentation: http://www.rubydoc.info/gems/websocket/
- Licenses: MIT
- Latest release: 1.2.11 (published over 1 year ago)
- Last Synced: 2025-12-11T12:33:33.866Z (about 13 hours ago)
- Versions: 24
- Dependent Packages: 75
- Dependent Repositories: 77,101
- Downloads: 172,289,679 Total
- Docker Downloads: 803,678,778
-
Rankings:
- Dependent repos count: 0.134%
- Downloads: 0.215%
- Dependent packages count: 0.392%
- Docker downloads count: 0.497%
- Average: 1.34%
- Stargazers count: 2.707%
- Forks count: 4.097%
- Maintainers (1)
proxy.golang.org: github.com/imanel/websocket-ruby
- Homepage:
- Documentation: https://pkg.go.dev/github.com/imanel/websocket-ruby#section-documentation
- Licenses:
- Latest release: v1.2.11 (published over 1 year ago)
- Last Synced: 2025-12-10T17:25:39.938Z (1 day ago)
- Versions: 25
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 2.773%
- Forks count: 3.66%
- Average: 6.703%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
Dependencies
- rake >= 0 development
- rspec ~> 3.7 development
- rubocop = 0.52.1 development
- rubocop-rspec = 1.21.0 development
- webrick >= 0 development
- actions/checkout v2 composite
- cadwallion/publish-rubygems-action master composite
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
Score: 30.345604893441568