Permalink
Browse files

fixing servers node-deliviery

  • Loading branch information...
1 parent 99af89c commit a4103edb2a0ea14d180f7738257de9240fee7cae @chaosprinz committed Feb 26, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 sockets.rb
View
@@ -5,8 +5,8 @@
puts "Starting socketserver"
-DB = Sequel.mysql 'socketv', user: 'root', pw: 'mohrhuhn55'
-nodes = DB[:node]
+DB = Sequel.mysql 'socketv', user: 'root', password: 'mohrhuhn55'
+nodetable = DB[:node]
EM.run do
EM::WebSocket.start(host: "0.0.0.0", port: 8080) do |ws|
@@ -16,11 +16,19 @@
}
ws.onclose {
puts "connection closed"
- ws.send "Schade, dass du endlich gehst, Client"
+ ws.send "Ich mach Feierabend"
}
ws.onmessage { |msg|
puts "Client sagt: " + msg;
- ws.send nodes.filter(msg.gsub /^give me /,"") if msg.starts_with? "give me "
+ if msg.start_with? "give me"
+ nodes = nodetable.filter(nid: msg.gsub(/^give me /,"").to_i).to_a
+ nodes.each do |node|
+ ws.send node[:title]
+ puts node
+ end
+ else
+ ws.send "\"" + msg + "\" hast gsagt"
+ end
}
end
end

0 comments on commit a4103ed

Please sign in to comment.