I have a small application serving connections (like chat). He catches the connection, captures the login from him, then listens to the data and passes it to each connection except the sender.
The problem is that I'm not a very advanced tester and I don’t know how to check it.
def serve(io)
io.puts("LOGIN\n")
user = io.gets.chomp
...
@mutex.synchronize { @chatters[user] = io }
loop do
incoming = io.gets
broadcast(incoming, io)
end
end
def broadcast(message="", sender)
@mutex.synchronize do
@chatters.each do |chatter|
socket = chatter[1]
if sock != sender
sock.print(message)
end
end
end
end
source
share