Skip to content

Instantly share code, notes, and snippets.

@elorest
Created March 27, 2017 18:43
Show Gist options
  • Save elorest/36356b9ccb538b888d9cb4aa5fb0ce11 to your computer and use it in GitHub Desktop.
Save elorest/36356b9ccb538b888d9cb4aa5fb0ce11 to your computer and use it in GitHub Desktop.
require "socket"
UNIXSocket.open("/tmp/cr.sock") do |sock|
puts "What is your name?"
name = gets
sock.puts name
puts sock.gets
sock.close
end
require "socket"
server = UNIXServer.new("/tmp/cr.sock")
while sock = server.accept
proc = ->(sock : UNIXSocket) do
spawn do
name = sock.gets
puts name
sock.puts "Hello #{name}."
sock.close
end
end
proc.call(sock)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment