Paul Klumpp 11 years ago
parent
commit
b84533faa1
5 changed files with 60 additions and 0 deletions
  1. 0 0
      cs_central-cl.rb
  2. 0 0
      cs_connector.rb
  3. 0 0
      socket_central.rb
  4. 60 0
      socket_poc.rb
  5. 0 0
      stomp-allinone-central.rb

+ 0 - 0
central.rb → cs_central-cl.rb


+ 0 - 0
connection.rb → cs_connector.rb


+ 0 - 0
sockcentral.rb → socket_central.rb


+ 60 - 0
socket_poc.rb

@@ -0,0 +1,60 @@
+#!/usr/bin/ruby
+
+require 'socket'
+
+
+def displaying(client, user)
+	
+	#client.puts "#{user} connected."
+	loop do
+		while line = $display_queue[user].pop
+			client.puts line
+		end
+		sleep 0.1
+	end
+	
+end
+
+
+def write(user, input)
+	$display_queue[user].push(input)
+end
+
+def inputting(c, user, input)
+	write(user, "You said: #{input}")
+	if input =~ /^w (.+)/
+		input = $1
+		write("paul_dev_eggdrop", "he said: #{input}")
+	end
+end
+
+def spawn_server
+	$display_queue = Hash.new
+	#$write_queue["paul_dev_eggdrop"] = ["lala", "okay"]
+
+	server = TCPServer.new 7337
+	Thread.abort_on_exception = true
+	
+	loop do
+		Thread.start(server.accept) do |c|
+			user = c.gets.chomp
+			puts "#{user} connected."
+			
+			$display_queue[user] = Array.new
+
+			# this thread reads what others want you to read .. 
+			Thread.new{ displaying(c, user) }
+			
+			# reading the client input ... to write it somewhere, possibly to the client himself.
+			while input = c.gets.chomp
+				inputting(c, user, input)
+			end
+		
+			c.close
+		end
+	end
+
+end
+
+
+spawn_server

+ 0 - 0
old-connection.rb → stomp-allinone-central.rb