Skip to content

Instantly share code, notes, and snippets.

@Hersha-Snips
Created March 8, 2012 16:19
Show Gist options
  • Save Hersha-Snips/2001858 to your computer and use it in GitHub Desktop.
Save Hersha-Snips/2001858 to your computer and use it in GitHub Desktop.
Ruby: Simple TCP Server
require 'socket' # Sockets are in standard library
server = TCPServer.new(1234)
begin
while connection = server.accept
while line = connection.gets
break if line =~ /quit/
puts line
connection.puts "Received!\n"
end
connection.puts "Closing the connection. Bye!\n"
connection.close
#server.close
end
rescue Errno::ECONNRESET, Errno::EPIPE => e
puts e.message
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment