windows - 在 Windows 中使用 ZeroMQ 的 Erlang
问题描述
是否可以在 Windows 中使用 Erlang 和 ZeroMQ?我需要制作 rep/req 客户端。我在网站上尝试了 Erlang 的所有绑定:zeromq.org,但没有任何效果。我只能在 Chumak 绑定中运行对客户端/服务器。但我需要代表/请求。当我尝试运行 req/rep 客户端和服务器时,我得到了这个:
req_client:main().
** exception exit: {noproc,
{gen_server,call,
[chumak_sup,
{start_child,
#{id => 'chumak_socket_my-req',restart => transient,
start => {chumak_socket,start_link,[req,"my-req"]}}},
infinity]}}
in function gen_server:call/3 (gen_server.erl, line 223)
in call from chumak_sup:start_socket/2 (chumak_sup.erl, line 30)
in call from req_client:main/0 (req_client.erl, line 9)
这是来自模块的代码:chumak_sup:
-spec start_socket(Type::socket_type(), Identity::string()) -> {ok, SocketPid::pid()} | {error, Reason::atom()}.
start_socket(Type, Identity) ->
ProcessId = get_child_id(Identity), %% generate an atom ?
case supervisor:start_child(?MODULE, #{
id=>ProcessId,
restart=> transient,
start=>{?SOCKET, start_link, [Type, Identity]}
}) of
{error, already_present} ->
supervisor:restart_child(?MODULE, ProcessId);
Res ->
Res
end.
start_socket(Type) ->
%% socket without identity not use supervisor because the identity
%% is used to localize process inside supervisor.
?SOCKET:start_link(Type, "").
这是客户端的代码:
%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at http://mozilla.org/MPL/2.0/.
-module(req_client).
-export([main/0]).
main() ->
application:start(chumak),
{ok, Socket} = chumak:socket(req, "my-req"),
case chumak:connect(Socket, tcp, "localhost", 5555) of
{ok, Pid} ->
send_messages(Socket, [
<<"Hello my dear friend">>,
<<"Hello my old friend">>,
<<"Hello all the things">>
]);
{error, Reason} ->
io:format("Connection Failed for this reason: ~p\n", [Reason]);
Reply ->
io:format("Unhandled reply for connect ~p \n", [Reply])
end.
send_messages(Socket, []) ->
send_messages(Socket, [
<<"Hello my dear friend">>,
<<"Hello my old friend">>,
<<"Hello all the things">>
]);
send_messages(Socket, [Message|Messages]) ->
case chumak:send(Socket, Message) of
ok ->
io:format("Send message: ~p\n", [Message]);
{error, Reason} ->
io:format("Failed to send message: ~p, reason: ~p\n", [Message, Reason])
end,
case chumak:recv(Socket) of
{ok, RecvMessage} ->
io:format("Recv message: ~p\n", [RecvMessage]);
{error, RecvReason} ->
io:format("Failed to recv, reason: ~p\n", [RecvReason])
end,
timer:sleep(1000),
send_messages(Socket, Messages).
我是编程新手。我不明白如何解决这个任务。
解决方案
推荐阅读
- excel - 防止特殊字符,但允许使用空格进行数据验证
- java - Java acm ComplexNumber 类无法实例化?
- html - 设置元素相对于父元素的高度 - 其中父元素是弹性框的一部分
- user-management - 在 express-gateway 中创建用户
- amazon-web-services - 为 appsync 创建本地开发环境
- html - 如何使 HTML 页面具有响应性?
- sql-server - 遵循教程后在“)”附近出现不正确的语法错误
- javascript - 单击概览按钮时在 Android 上隐藏浏览器页面内容
- java - 匹配字符串 ArrayList 中的模式
- javascript - _idi_的MongoDB E11000重复键错误