chumak icon indicating copy to clipboard operation
chumak copied to clipboard

Re-Implement zguide examples in Chumak

Open drozzy opened this issue 7 years ago • 8 comments

Re-implement all the zguide Erlang examples in Chumak: https://github.com/booksbyus/zguide/tree/master/examples

This will serve to document the library and iron out any quirks in the library.

drozzy avatar Mar 30 '17 02:03 drozzy

Looking for contributors.

drozzy avatar Jun 17 '19 14:06 drozzy

if you could get me an example of actually using chumak in a gen_server, I'd happily help sort ouf the rest of the docs. The examples/ aren't idiomatic for some people, even those experienced in Erlang, to get as far as hello world.

mk270 avatar Jun 26 '19 16:06 mk270

I haven’t looked into this in a while, so I’m afraid I can’t help. Hopefully someone can figure out how to make it idiomatic. Feel free to hack the core code. My intent was to just provide a starting point.

drozzy avatar Jul 06 '19 13:07 drozzy

I would like to help with this, @mk270 could you tell you mean by idiomatic examples, I have tried the following code example and it is working:

The server module is:

-module(hwserver).
-export([main/0]).

main() ->
    application:start(chumak),
    {ok, Socket} = chumak:socket(rep, "my-rep"),
    io:format("~p", [Socket]),
    {ok, Pid} = chumak:bind(Socket, tcp, "localhost", 5555),
    loop(Socket).

loop(Socket) ->
    {ok, RecvMessage} = chumak:recv(Socket),

    io:format("Received request : ~p\n", [RecvMessage]),

    timer:sleep(1000),

    chumak:send(Socket, "World"),
    loop(Socket).

and the client module is:

-module(hwclient).
-export([main/0]).

main() ->
    application:start(chumak),
    {ok, Socket} = chumak:socket(req, "my-req"),
    {ok, Pid} = chumak:connect(Socket, tcp, "localhost", 5555),
    loop(Socket).


loop(Socket) ->
    chumak:send(Socket, "Hello"),
    {ok, RecvMessage} = chumak:recv(Socket),
    io:format("Recv Reply: ~p\n", [RecvMessage]),
    loop(Socket).

shishirpy avatar Jul 02 '21 02:07 shishirpy

@drozzy what is the equivalent of socket.close() in chumak? I am trying to implement the lazy pirate pattern, where one has to close the socket and restart a new one in no response arrives in fixed timeout.

shishirpy avatar Sep 13 '21 02:09 shishirpy

As I remember there was some discussion similar to this before, but I don't think anything was actually decided: https://github.com/zeromq/chumak/pull/19 https://github.com/zeromq/chumak/issues/18

drozzy avatar Sep 13 '21 07:09 drozzy

@drozzy any idea how to have an unblocking receive command? Trying to implement msreader https://github.com/booksbyus/zguide/blob/master/examples/Erlang/msreader.es

shishirpy avatar Oct 16 '22 04:10 shishirpy

@shishirpy you may have more luck on Erlang discussion forums: https://www.erlang.org/community I'm not actively maintaining this - I only try to keep up with MRs.

drozzy avatar Oct 17 '22 00:10 drozzy