I used to and wanted to use the -archetype architecture described here . In this process, they run as client, server, and exchange data. Now the server has the following code (also indicated in the provided link): nanomsg
IPC
SURVEY
int server (const char *url)
{
int sock = nn_socket (AF_SP, NN_SURVEYOR);
assert (sock >= 0);
assert (nn_bind (sock, url) >= 0);
sleep(1);
int sz_d = strlen(DATE) + 1;
printf ("SERVER: SENDING DATE SURVEY REQUEST\n");
int bytes = nn_send (sock, DATE, sz_d, 0);
assert (bytes == sz_d);
while (1)
{
char *buf = NULL;
int bytes = nn_recv (sock, &buf, NN_MSG, 0);
if (bytes == ETIMEDOUT) break;
if (bytes >= 0)
{
printf ("SERVER: RECEIVED \"%s\" SURVEY RESPONSE\n", buf);
nn_freemsg (buf);
}
}
return nn_shutdown (sock, 0);
}
Since the socket type NN_SURVEYOR
, while
-loop does not wait nn_recv
. For the client, the socket type is NN_RESPONDENT
, and therefore, while the loop in the client is waiting nn_recv
.
Now that the while loop runs continuously and indefinitely, CPU utilization is increased to 99%. Could you tell me that there is another way to make geodetic architecture with nanomsg
.