snipplets.dev/snipplets/code/Crystal/UNIXSockets/client.cr
2023-08-05 22:45:06 +03:00

25 lines
381 B
Crystal

require "socket"
# connect to socket
sock = UNIXSocket.new("/tmp/myapp.sock")
loop do
print "Enter command [help, start, run]: "
# get string from terminal input
string = gets.not_nil!.to_s
if string == "q"
break
end
# send string to server
sock.puts "#{string}\n"
# get response from server & print
response = sock.gets
puts response
end
sock.close