作者:江苏经贸学院 | 来源:互联网 | 2023-06-20 10:37
https://github.com/nanomsg/nanomsg/issues/271https://github.com/nanomsg/nanomsg/issu
https://github.com/nanomsg/nanomsg/issues/271
https://github.com/nanomsg/nanomsg/issues/399
http://250bpm.com/blog:14
http://nanomsg.freelists.narkive.com/7os9qW2V/a-stupid-load-balancing-question
Just use REQs, REPs and a device in the middle. When creating sockets
for the device, use AF_SP_RAW family (AF_SP_RAW+REQ is what's called
DEALER in ZeroMQ parlance, and AF_SO_RAW+REP corresponds to ROUTER).
from above urls ,it seems that with nn_device , multiple client can connnect multiple server
from nn_device description, nn_device only connect two sockets:
http://nanomsg.org/v1.0.0/nn_device.3.html
EXAMPLE
int s1 = nn_socket (AF_SP_RAW, NN_REQ);
nn_bind (s1, "tcp://127.0.0.1:5555");
int s2 = nn_socket (AF_SP_RAW, NN_REP);
nn_bind (s2, "tcp://127.0.0.1:5556");
nn_device (s1, s2);
I want to distribute the load on server side.
the topology is as following:
1 2 3 4 5 6 7 8 9
| |----------------|
| |
req1----| |-----rep1
req2----|nn_device(s1,s2)|-----rep2
req3----| |-----rep3
| |
| |
| |
|----------------| |
are the following pseudocodes correct?
step 1: create nn_device
int s1 = nn_socket (AF_SP_RAW, NN_REQ);
nn_bind (s1, "tcp://127.0.0.1:5555");
int s2 = nn_socket (AF_SP_RAW, NN_REP);
nn_bind (s2, "tcp://127.0.0.1:5556");
nn_device (s1, s2);
step 2 :create multi servers(rep)
int rep1 = nn_socket (AF_SP, NN_REP);
int rep2 = nn_socket (AF_SP, NN_REP);
int rep3 = nn_socket (AF_SP, NN_REP);
nn_connect (rep1, "tcp://127.0.0.1:5555");
nn_connect (rep2, "tcp://127.0.0.1:5555");
nn_connect (rep2, "tcp://127.0.0.1:5555");
step 3:create mutli client (req)
int req1 = nn_socket (AF_SP, NN_REQ);
int req2 = nn_socket (AF_SP, NN_REQ);
int req3 = nn_socket (AF_SP, NN_REQ);
nn_connect (req1, "tcp://127.0.0.1:5556");
nn_connect (req2, "tcp://127.0.0.1:5556");
nn_connect (req2, "tcp://127.0.0.1:5556");
thanks a lot
该提问来源于开源项目:nanomsg/nanomsg
Hmm.. it seems I was wrong about about device — it blocks forever as long
as the sockets are open. (Just checked the code, and have removed the
pause() from my demo.
Looking again at your code, I just realized something… your IP addresses do
not match!
The IP address you use use for the bind side is the local IP address on
the server. You can even omit it to listen on all interfaces - e.g.
tcp://:5556 will cause the server to listen on every network interface on
TCP port 5556.
The IP address you use for connect is the remote IP address.
I’m about 95% certain that this is the problem.
On Wed, Nov 23, 2016 at 12:10 AM, kuncao notifications.com wrote:
your device is exiting main. you need to pause there without exiting.
pause() is a good unix function for this.
I add pause in my c++ code,but it seem to I have to use control +c twice
to shutdown device,without pause(),only once control +c to shutown the
device.
-------------------with pause()test begin --------------------------------
szv1000082629:/home/nanoprorpc/nanorpc # ./device_server
s1 value is : 0
s2 value is : 1
^CExiting on ^C control c
after nn_device init : -1
afdadf
adfsasdf
wd
ddd
^CExiting on ^C control c
-------------------with pause() test end--------------------------------
afdadf and other letters is to verify the device can be shutdown after
pause()
-------------------without pause() test begin-------------------------
-------szv1000082629:/home/nanoprorpc/nanorpc # ./device_server
s1 value is : 0
s2 value is : 1
^CExiting on ^C control c
after nn_device init : -1
-------------------without pause() test end---------------------------
my code:
include
include
include
include
include
include
void OnExit(int sig)
{
nn_term();//this is added by jackcao at 20161123
// to term the socket s1 s2
//and may term other socket created by nanomsg in this server
std::cerr <<"Exiting on ^C " <<"control c" <}
int main(int argc, char *argv[])
{
signal(SIGINT, OnExit);
int s1 = nn_socket (AF_SP_RAW, NN_REP);
std::cerr <<"s1 value is : " <nn_bind (s1, "tcp://10.120.229.120:5555");
int s2 = nn_socket (AF_SP_RAW, NN_REQ);
std::cerr <<"s2 value is : " <nn_bind (s2, "tcp://10.120.229.120:5556");
int sd=nn_device (s1, s2);
std::cerr <<"after nn_device init : " <//pause();
return 0;
}
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/nanomsg/nanomsg/issues/832#issuecomment-262453754,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPDfYB4aXuW2zkuXlhXYuRlOPX3lZr9ks5rA_ThgaJpZM4K33Zp
.