Created
March 27, 2017 18:43
-
-
Save elorest/36356b9ccb538b888d9cb4aa5fb0ce11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
UNIXSocket.open("/tmp/cr.sock") do |sock| | |
puts "What is your name?" | |
name = gets | |
sock.puts name | |
puts sock.gets | |
sock.close | |
end |
This file contains hidden or 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" | |
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