snipplets.dev/code/Crystal/UNIXSockets/client.cr
2023-09-26 22:05:13 +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