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

25 lines
381 B
Crystal
Raw Normal View History

2023-06-18 22:07:49 +03:00
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