Note that there are some explanatory texts on larger screens.

plurals
  1. POzeromq conversion between datatypes
    primarykey
    data
    text
    <p>Hello I am trying to understand and learn how to work with ZeroMQ and while this could be basic, I didn't find a way to fix it. In this code, I am trying to create a server to forward messages from one client to another one. The server compiled just fine but there are some major issues (almost all of them regarding datatypes) so I couldn't even test my server.</p> <p><strong>server.cpp:</strong></p> <pre><code>#include "zmq.hpp" #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;unistd.h&gt; int main () { zmq::message_t board (9); zmq::context_t context (1); zmq::socket_t socket1 (context, ZMQ_REP); socket1.bind ("tcp://*:20000"); zmq::socket_t socket2 (context, ZMQ_REP); socket1.bind ("tcp://*:20001"); int jogo=9; while (jogo) { zmq::message_t request; if (jogo%2!=0) { socket1.recv (&amp;request); memcpy ((void *) board.data (), request.data(), 9); socket2.send (board); } else { socket2.recv (&amp;request); memcpy ((void *) board.data (), request.data(), 9); socket1.send (board); } --jogo; } return 0; } </code></pre> <p><strong>jogo_client.cpp</strong></p> <pre><code>#include "zmq.hpp" #include &lt;string&gt; #include &lt;iostream&gt; int main () { int player,port=20000,jogo=9,ganhou=0; std::string game; std::cin &gt;&gt; player; port+=player; zmq::context_t context (1); zmq::socket_t socket (context, ZMQ_REQ); std::cout &lt;&lt; "Connecting to game server…" &lt;&lt; std::endl; //-std=gnu++11 socket.connect (std::string("tcp://localhost:")+std::to_string(port)); zmq::message_t board (9); if(player) { while(jogo) { if (jogo%2!=0) { memcpy ((void *) board.data (), "Hi from 1", 9); std::cout &lt;&lt; "Sending Hi" &lt;&lt; std::endl; socket.send (board); } else { socket.recv (&amp;board); memcpy ((void *) ,game, request.data (), 9); std::cout &lt;&lt; "Got from 2: " &lt;&lt; std::endl; std::cout &lt;&lt; game &lt;&lt; std::endl; } --jogo; } } else { while(jogo) { if (jogo%2!=0) { socket.recv (&amp;board); memcpy ((void *) ,game, request.data (), 9); std::cout &lt;&lt; "Getting from 2 " &lt;&lt; std::endl; std::cout &lt;&lt; game &lt;&lt; std::endl; } else { emcpy ((void *) board.data (), "Hi from 2", 9); std::cout &lt;&lt; "Sending Hi" &lt;&lt; std::endl; socket.send (board); } --jogo; } } return 0; } </code></pre> <p>compile errors:</p> <pre><code>jogo_client.cpp: In function ‘int main()’: jogo_client.cpp:14:73: error: no matching function for call to ‘zmq::socket_t::connect(std::basic_string&lt;char&gt;)’ jogo_client.cpp:14:73: note: candidate is: In file included from jogo_client.cpp:1:0: zmq.hpp:384:21: note: void zmq::socket_t::connect(const char*) zmq.hpp:384:21: note: no known conversion for argument 1 from ‘std::basic_string&lt;char&gt;’ to ‘const char*’ jogo_client.cpp:29:26: error: expected primary-expression before ‘void’ jogo_client.cpp:29:26: error: expected ‘)’ before ‘void’ jogo_client.cpp:43:26: error: expected primary-expression before ‘void’ jogo_client.cpp:43:26: error: expected ‘)’ before ‘void’ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload