Created
March 8, 2012 16:19
-
-
Save Hersha-Snips/2001858 to your computer and use it in GitHub Desktop.
Ruby: Simple TCP Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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