How to Write a TCP Echo Server in Ruby

In ruby you have lowlevel access to all the same methods that you do in C. But you also have some higher level sugar on top of that - and a program that does the same as the c version, is almost as concise as it is in javascript. You get no free concurrency here though - you still need multiple processes or threads to achieve that.

require 'socket'
a = TCPServer.new('', ARGV.first)
connection = a.accept
loop do
  connection.write connection.recv(1024)
end

Related Posts