百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

web-socket-ruby

> 编程语言
开源

Ruby 中的 HTML5 Web Socket 服务器/客户端实现

369 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Ruby 中的 HTML5 Web Socket 服务器/客户端实现

HTML5 Web Socket server/client implementation in Ruby.

For server, em-websocket ( https://github.com/igrigorik/em-websocket ) may be a better choice, especially if you want to use EventMachine.

  • How to run sample
  • Run sample Web Socket server (echo server) with: $ ruby samples/echo_server.rb localhost 10081

  • Run sample Web Socket client and type something: $ ruby samples/stdio_client.rb ws://localhost:10081 Ready hoge Sent: "hoge" Received: "hoge"

  • Usage example

Server:

Runs the server at port 10081. It allows connections whose origin is example.com.

server = WebSocketServer.new(:port => 10081, :accepted_domains => ["example.com"]) server.run() do |ws| # The block is called for each connection. # Checks requested path. if ws.path == "/" # Call ws.handshake() without argument first. ws.handshake() # Receives one message from the client as String. while data = ws.receive() puts(data) # Sends the message to the client. ws.send(data) end else # You can call ws.handshake() with argument to return error status. ws.handshake("404 Not Found") end end

Client:

Connects to Web Socket server at host example.com port 10081.

client = WebSocket.new("ws://example.com:10081/")

Sends a message to the server.

client.send("Hello")

Receives a message from the server.

data = client.receive() puts(data)

  • Supported WebSocket protocol versions

WebSocketServer class (server) accepts version hixie-75, hixie-76, hybi-07, hybi-10. WebSocket class (client) speaks version hixie-76.

  • Tips: JavaScript client implementation

Google Chrome Dev Channel natively supports Web Socket. For other browsers, you can use an implementation using Flash: http://github.com/gimite/web-socket-js/tree/master

  • WebSocket protocol versions

The server supports the protocol defined in RFC 6455, draft versions hixie-75 and hixie-76.

The client speaks draft version hixie-76.

  • License

New BSD License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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