Created
May 4, 2010 03:05
-
-
Save jordandobson/388896 to your computer and use it in GitHub Desktop.
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
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 |
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
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