snipplets.dev/code/Crystal/UNIXSockets/by_faustinoaq/client.cr
2023-09-26 22:05:13 +03:00

29 lines
331 B
Crystal

require "socket"
client = UNIXSocket.new("/tmp/myapp.sock")
Signal::INT.trap {
client.puts "quit"
exit
}
print "name: "
name = gets.to_s
spawn {
loop {
msg = client.gets
if msg
puts msg
else
puts "server closed"
exit
end
}
}
loop {
msg = gets.to_s
client.puts "#{name}: #{msg}"
}