Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 204

How to gracefully terminate a socket server?

$
0
0

If I have a server function that is listening to a port in an infinite loop, how do I stop it? If i do ctrl+c it terminates the process and the program does not get a chance to destroy the socket pointer. Whats the standard of dealing with this?

#include <czmq.h>int main(int argc, char **argv){    setvbuf(stdout, NULL, _IONBF, 0);    zsock_t *responder = zsock_new(ZMQ_REP);    int r = zsock_bind(responder, "tcp://localhost:5555");    if (r != 5555){        printf("Failed to bind\n");    }    while(true){        char *msg = zstr_recv(responder);        if (!strcmp(msg, "Bonjour!")){            zstr_send(responder, "Ouais!");        }        free(msg);        printf(".\n");    }    zsock_destroy(&responder);}

Viewing all articles
Browse latest Browse all 204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>