Skip to content

Instantly share code, notes, and snippets.

@jordandobson
Created May 4, 2010 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordandobson/388896 to your computer and use it in GitHub Desktop.
Save jordandobson/388896 to your computer and use it in GitHub Desktop.
require 'socket'
class ChatClient
def initialize
@server = TCPSocket.open( 'localhost', 36963 )
connectToServer
end
def connectToServer
loop do
puts "\nSTART ////////////////////"
if message = @server.gets
puts "[Recieved]: #{message}"
end
puts "I wait until you say something..."
###
# I don't really want it to block here I don't think.
if line = gets
@server.puts( line )
end
puts "END ////////////////////"
end
end
end
client = ChatClient.new
require 'gserver'
class ChatServer < GServer
def initialize(*args)
super(*args)
@@client_id = 0
@@chat = []
end
def serve( io )
@@client_id += 1
my_client_id = @@client_id
io.puts( "CLIENT #{my_client_id} - time: #{Time.now.to_s}" )
loop do
# Is server okay to Block so it listens for messages?
line = io.readline
# I want to push out to all clients here.
io.puts( "Sever got: #{line}" )
# Make Sure Server Prints it here.
puts line
end
end
end
server = ChatServer.new(36963)
server.audit = true
server.start
server.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment