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}"
}
