1
호스트 이름과 포트를 명령 줄에서 gen_tcp.connect로 전달하고 싶습니다. 모든 것을 '로컬 호스트 것은'잘 작동 하드 코딩에 의해, 그러나명령 줄에서 gen_tcp에 호스트 이름을 전달하는 방법
** (exit) :badarg (kernel) gen_tcp.erl:149: :gen_tcp.connect/4 (mycomm) lib/application.ex:14: MyComm.Application.connect/2 (elixir) lib/kernel/cli.ex:76: anonymous fn/3 in Kernel.CLI.exec_fun/2
: badarg 오류 : 위의 예제를 실행
는defmodule MyComm.Application do
use Application
def main(args \\ []) do
{options, _, _} = parse_args(args)
connect(options[:host], options[:port])
# connect('localhost', options[:port])
end
def connect(host, port) do
opts = [:binary, active: false]
{:ok, socket} = :gen_tcp.connect(host, port, opts)
:gen_tcp.send(socket, "123\r\n")
end
def parse_args(args \\ []) do
OptionParser.parse(args, switches: [host: :string, port: :integer])
end
end
됩니다. 여기에 무엇이 누락 되었습니까?
예, 그게 전부입니다. 감사. – Rob