nng
nng copied to clipboard
examples demo nng under windows
Dears, I'm following this tutorial to learn nng, https://nanomsg.org/gettingstarted/nng/index.html the problem is, all the command are under linux, as for example,
Execution
./pipeline node0 ipc:///tmp/pipeline.ipc & node0=$! && sleep 1
./pipeline node1 ipc:///tmp/pipeline.ipc "Hello, World!"
./pipeline node1 ipc:///tmp/pipeline.ipc "Goodbye."
kill $node0
how can I use these examples under windows? what is the windows equivalent statement of the following,
ipc:///tmp/pipeline.ipc & node0=$!
These are basic shell constructs for UNIX. We could probably port them to power shell but sadly I'm not an expert with that.
The & at the end of a command makes the command in front of it run in the background. The !$ is expanded to the process id of that command and kill command terminates the process.
You could run each of the simple commands in a window of their own (without the UNIX shell bits) and then just kill them all when you are done using the task manager. That might be the easiest for a Windows user.
On Linux, &
runs the command in the background. On Windows, the equivalent is here: https://superuser.com/questions/198525/how-can-i-execute-a-windows-command-line-in-background
start /b pipeline node0 ...
etc.
I think :-)
Oh sleep 1 means to sleep a second (after backgrounding the prior command). This is to give the server process enough time to start up properly before starting client processes.
If someone wants to contribute a power shell equivalent in a PR I would be grateful.
OK, Dears, let's get specific about this WHERE-TO-START thing, e.g. ./pipeline.exe node1 ipc://test "Hello, World!"
int
node1(const char *url, char *msg)
{
int sz_msg = strlen(msg) + 1; // '\0' too
nng_socket sock;
int rv;
int bytes;
if ((rv = nng_push0_open(&sock)) != 0) {
fatal("nng_push0_open", rv);
}
//NNG_ECONNREFUSED == 6;
NNG_EPEERAUTH;
if ((rv = nng_dial(sock, url, NULL, 0)) != 0) {
fatal("nng_dial", rv);
}
printf("NODE1: SENDING \"%s\"\n", msg);
if ((rv = nng_send(sock, msg, strlen(msg)+1, 0)) != 0) {
fatal("nng_send", rv);
}
//sleep(1); // wait for messages to flush before shutting down
Sleep(1000);
nng_close(sock);
return (0);
}
in this example, the nng_dial always returns NNG_ECONNREFUSED whatever url chars provided, what is the correct url string under windows for ipc? if we don't use ipc, are there any other examples about running this application? and HOW?
You have to run the server first. It can take a dozen milliseconds or so from starting the server before it has the socket ready for clients to connect.
On windows IPC URLs can be almost anything as they live in their own namespace. For example ipc:///my-application
You could also use tcp like tcp://127.0.0.1:1234 - which would mean TCP port 1234 on the loop back interface.
@gdamore Great thanks for your reply, but how can I start this nng server as you mentioned? I see there is a tcp project and in the main file it gives
trantest_test_extended("tcp://127.0.0.1:%u", check_props_v4);
but how can I use this tcp.exe? I search on the website and find several videos about nanomsg, but none of them are useful for a newbie like me. Actually we don't need info about what nng or nanomsg is and how it works or so, we just need a start point with couple of commands or application demos that can really work immediately. By the way, there are lots of *.exe test files, are there any demos showing how to use them?
I figured it out somehow, though not familiar with it yet. Ref. https://github.com/SpaceView/nng-examples