Building a Simple TCP Server : TCP Server « Network « Ruby

Building a Simple TCP Server

require 'socket'

server =

while connection = server.accept
  while line = connection.gets
    break if line =~ /quit/
    puts line
    connection.puts "Received!"

  connection.puts "Closing the connection. Bye!"

# To test
# telnet 1234


Related examples in the same category

1.Multi-Client TCP Servers
2.To create a simple Web server, you can accept connections on the IP address and the port number 80
3.Creating a Web Server with thread support