Created
February 1, 2014 21:35
-
-
Save mariusavram91/8759276 to your computer and use it in GitHub Desktop.
Websocket server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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