-
-
Save activeliang/f7a50de0e171a5770c8eeff6f5cfaea5 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