zeromq / chumak

Pure Erlang implementation of ZeroMQ Message Transport Protocol.
Mozilla Public License 2.0
197 stars 47 forks source link

exception exit #33

Closed luckyupshot closed 5 years ago

luckyupshot commented 5 years ago

Hello. I tried to run req client and req/rep server. And I got an error: req_server: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_server:main/0 (req_server.erl, line 9)

Can you help me please?

DavidAlphaFox commented 5 years ago

I think you should use application:start(chumak) to start chumak_sup process. If you had already started the application, can you post more details please.

luckyupshot commented 5 years ago

Here is a code of client:

%% 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).

How to know if chumak application starts or no? I see application:start(chumak) in the begining of client so it seems it must start. I tried to use another client it called: "pair_client". It also use chumak. And it works. But "req_client" doesn't.

luckyupshot commented 5 years ago

I think you should use application:start(chumak) to start chumak_sup process. If you had already started the application, can you post more details please.

Thank you for your answer. I use Erlang in Windows not in Linux.May be this is a problem and applcation(chumak):start doesn't work. So now I tried to start chumak manually in terminal. I entered function chumak:start(1,1) in terminal (I don't know what arguments to use) and after that I started server: repserver:main(). And server started!!!! I did the same with client and it also started. I will try to insert chumak start in code. For now I think as problem is solved. But please tell what arguments to use in chumak:start(,_).

DavidAlphaFox commented 5 years ago

I think you should use application:start(chumak) to start chumak_sup process. If you had already started the application, can you post more details please.

Thank you for your answer. I use Erlang in Windows not in Linux.May be this is a problem and applcation(chumak):start doesn't work. So now I tried to start chumak manually in terminal. I entered function chumak:start(1,1) in terminal (I don't know what arguments to use) and after that I started server: rep_server:main(). And server started!!!! I did the same with client and it also started. I will try to insert chumak start in code. For now I think as problem is solved. But please tell what arguments to use in chumak:start(,).

It's my fault, the chumak application doesn't start any supervisor by application:start(chumak). The supervisor is started by chumak:start and this function will ignore the arguments that are passed in. So you can give any arguments to this function.

drozzy commented 5 years ago

I’m going to close this for now. Open another issue if you still have questions.