Skip to content

Instantly share code, notes, and snippets.

@heftig
Created June 14, 2012 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heftig/2932985 to your computer and use it in GitHub Desktop.
Save heftig/2932985 to your computer and use it in GitHub Desktop.
require 'socket'
sockpath = "/tmp/foosock"
if ARGV.first == "server"
socket = UNIXServer.new sockpath
begin
while client_sock = socket.accept do
Thread.start do
puts "New connection"
while line = client_sock.gets
client_sock.write line
end
client_sock.close
end
end
ensure
File.unlink sockpath
end
else
socket = UNIXSocket.new sockpath
Thread.start do
while line = socket.gets
puts line
end
end
while line = gets
socket.write line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment