Created
June 14, 2012 21:12
-
-
Save heftig/2932985 to your computer and use it in GitHub Desktop.
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
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