Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Last active August 29, 2015 14:02
Show Gist options
  • Save MaxPleaner/71b2a28c4c92ffc56b5e to your computer and use it in GitHub Desktop.
Save MaxPleaner/71b2a28c4c92ffc56b5e to your computer and use it in GitHub Desktop.
broken loop in ruby socket
require 'socket'
server = TCPServer.new(2000)
# An "echo server" read a single line of input from the client, echoes that
# input line back to the client, hangs up, and listens for a new connection.
def echo_prompt(client)
client.puts "Enter some input to echo"
input = client.gets.chomp
client.puts "You said \"#{input}\"."
end
loop do
puts "Waiting for new clients on port #{server.addr[1]}..."
client = server.accept
echo_prompt(client)
# client.puts "Want to do echo some more text? (type y for yes, anything else for no)"
# response = client.gets.chomp
# if response == "y"
# echo_prompt(client)
# else
# client.close
# end
client.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment