web-socket-rubyWeb Socket 的 Ruby 實(shí)現(xiàn)
這是 Ruby 對(duì) WebSocket 的實(shí)現(xiàn),示例代碼:
# 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
評(píng)論
圖片
表情
