Created
March 18, 2013 21:33
-
-
Save neomantra/5191016 to your computer and use it in GitHub Desktop.
Sample echo client for nanomsg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -o echo_client -g examples/echo_client.c -I ../nanomsg/src -L ../nanomsg/build -l nanomsg | |
// LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../nanomsg/build" ./echo_client foobar | |
#include <assert.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include "nn.h" | |
#include "reqrep.h" | |
int main( int argc, const char* argv[] ) | |
{ | |
printf( "...client started... '%s'\n", argv[1] ); | |
int s = nn_socket( AF_SP, NN_REQ ); | |
printf("socket returned: %d\n", s ); | |
assert( s >= 0 ); | |
int rc = nn_connect( s, "tcp://127.0.0.1:5556" ); | |
printf("nn_connect returned: %d\n", rc ); | |
assert( rc > 0 ); | |
int sz = nn_send( s, argv[1], strlen(argv[1]), 0 ); | |
printf("nn_send returned: %d\n", sz ); | |
assert( sz > 0 ); | |
char buf[100]; | |
sz = nn_recv( s, buf, 100, 0 ); | |
printf("nn_recv returned: %d\n", sz ); | |
assert( sz > 0 ); | |
printf( "received %s\n", buf ); | |
printf( "...client done...\n" ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment