Skip to content

Instantly share code, notes, and snippets.

@llekn llekn/server.rb
Created Mar 17, 2017

Embed
What would you like to do?
Websocket server using Eventmachine
require 'em-websocket'
EM.run do
EM::WebSocket.run(host: '0.0.0.0', port: 8080) do |ws|
ws.onopen do |handshake|
puts 'WebSocket connection open'
# Access properties on the EM::WebSocket::Handshake object, e.g.
# path, query_string, origin, headers
# Publish message to the client
ws.send "Hello Client, you connected to #{handshake.path}"
end
ws.onclose { puts 'Connection closed' }
ws.onmessage do |msg|
puts "Recieved message: #{msg}"
ws.send "Pong: #{msg}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.