21 lines
440 B
Ruby
21 lines
440 B
Ruby
require 'socket'
|
|
server = TCPServer.new(12321)
|
|
|
|
while (connection = server.accept)
|
|
Thread.new(connection) do |conn|
|
|
port, host = conn.peeraddr[1,2]
|
|
client = "#{host}:#{port}"
|
|
puts "#{client} is connected"
|
|
begin
|
|
loop do
|
|
line = conn.readline
|
|
puts "#{client} says: #{line}"
|
|
conn.puts(line)
|
|
end
|
|
rescue EOFError
|
|
conn.close
|
|
puts "#{client} has disconnected"
|
|
end
|
|
end
|
|
end
|