web-socket-ruby 介绍
这是 Ruby 对 WebSocket 的实现,示例代码:
# 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
web-socket-ruby 官网
https://github.com/sblackstone/web-socket-ruby
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。