Skip to content

Instantly share code, notes, and snippets.

@RickCarlino
Created November 2, 2013 05:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RickCarlino/7275797 to your computer and use it in GitHub Desktop.
Save RickCarlino/7275797 to your computer and use it in GitHub Desktop.
Bi-directional TCP socket in Ruby
#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