snipplets.dev/code/Crystal/UNIXSockets/by_faustinoaq/client.cr

29 lines
331 B
Crystal
Raw Normal View History

2023-06-18 22:08:38 +03:00
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}"
}