29 lines
331 B
Crystal
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}"
|
|
}
|