Created
November 2, 2013 05:14
-
-
Save RickCarlino/7275797 to your computer and use it in GitHub Desktop.
Bi-directional TCP socket in Ruby
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
#Jeepers, this standard library has everything! | |
require 'socket' | |
server = TCPServer.new "127.0.0.1" , 4000 | |
while connection = server.accept | |
Thread.new(connection) do |client| | |
while (client_input = client.gets.chomp) | |
puts client_input | |
end | |
end | |
Thread.new(connection) do |client| | |
while (server_input = gets.chomp) | |
client.puts server_input | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment