Erlang с ZeroMQ в Windows - PullRequest
       5

Erlang с ZeroMQ в Windows

1 голос
/ 12 марта 2019

Возможно ли использовать Erlang с ZeroMQ в Windows?Мне нужно сделать rep / req client.Я перепробовал все привязки для Erlang на сайте: zeromq.org, но ничего не работает.Я мог только запустить пару клиент / сервер при привязке к чумакуНо мне нужен респ / рек.Когда я пытаюсь запустить клиент 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).

Я новичок в программировании.Я не могу понять, как решить эту задачу.

...