Skip to content

Instantly share code, notes, and snippets.

@mariusavram91
Created February 1, 2014 21:35
Show Gist options
  • Save mariusavram91/8759276 to your computer and use it in GitHub Desktop.
Save mariusavram91/8759276 to your computer and use it in GitHub Desktop.
Websocket server
STDOUT.sync=true
require 'rubygems'
require 'em-websocket'
EM.run {
EM::WebSocket.run(:host => "0.0.0.0",:port => 8080) do |ws|
ws.onopen { |handshake|
puts "WebSocket connection open"
ws.send "Connected"
}
ws.onclose { puts "Connection closed" }
ws.onmessage { |cmd|
begin
IO.popen( cmd ) do |stdin, stdout, pid|
begin
stdin.each { |line|
ws.send "Result: #{line}"
}
end
end
end
}
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment