连接到TCP客户端Elixir

时间:2017-04-24 21:00:55

标签: erlang elixir

尝试连接到TCP服务器,发送命令并获得响应。

我在Ruby中有这样的东西

TCPSocket.open("127.0.0.1", 3344)
 s.send(JSON.dump({"id" => 1, "method" => "Responder.Status", "params" => [""]}),0)

任何能够在Elixir中实现类似(或更强大)功能的文档/库的指针?

1 个答案:

答案 0 :(得分:3)

对于TCP连接,可以使用erlang标准库gen_tcp

{:ok, socket} = :gen_tcp.connect('localhost', 6379, [:binary])
data = {"id" => 1, "method" => "Responder.Status", "params" => [""]}
:ok = :gen_tcp.send(socket, Poison.encode!(data))
:ok = :gen_tcp.close(socket)