Last active
August 29, 2015 14:02
-
-
Save MaxPleaner/71b2a28c4c92ffc56b5e to your computer and use it in GitHub Desktop.
broken loop in ruby socket
This file contains hidden or 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' | |
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