Open renukamanavalan opened 1 year ago
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <zmq.h>
const char *zmq_path = "tcp://127.0.0.1:5555";
int main(int argc, char **argv)
{
int opt;
int run_server = 0;
void *zmq_ctx = NULL;
void *zmq_sck = NULL;
// Parse command line arguments
while ((opt = getopt(argc, argv, "s")) != -1) {
switch (opt) {
case 's':
run_server = 1;
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-s]\n", argv[0]);
exit(-1);
}
}
// Create a new ZeroMQ context
zmq_ctx = zmq_ctx_new();
if (run_server != 0) {
// Server: Create a REP socket
zmq_sck = zmq_socket(zmq_ctx, ZMQ_REP);
printf("Binding to server %s\n", zmq_path);
zmq_bind(zmq_sck, zmq_path);
printf("Bound to server %s\n", zmq_path);
// Wait for messages (for example purposes)
while (1) {
char buffer[256];
zmq_recv(zmq_sck, buffer, sizeof(buffer), 0); // Receive a message
printf("Received: %s\n", buffer); // Print the received message
zmq_send(zmq_sck, "ACK", 3, 0); // Send an acknowledgment
}
}
else {
// Client: Create a REQ socket
zmq_sck = zmq_socket(zmq_ctx, ZMQ_REQ);
printf("Connecting to server %s\n", zmq_path);
zmq_connect(zmq_sck, zmq_path);
printf("Connected to server %s\n", zmq_path);
// Send a message to the server
zmq_send(zmq_sck, "Hello", 5, 0);
char buffer[256];
zmq_recv(zmq_sck, buffer, sizeof(buffer), 0); // Wait for acknowledgment
printf("Received: %s\n", buffer); // Print acknowledgment
}
// Sleep for a while
printf("Sleeping\n");
sleep(3600);
printf("Closing socket...\n");
zmq_close(zmq_sck);
printf("Destroying context ...\n");
zmq_ctx_destroy(zmq_ctx);
return 0;
}
Issue description
Simple ZMQ model using ZMQ_CLIENT & ZMQ_SERVER fails with following assertion.
Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110)
Code is pretty simple. Invoke it in client / server mode. Server: Creates sock, binds and sleep for an hour before exiting Client: Creates sock, connect & sleep
The assertion happens while the main thread is sleeping.
BTW, I saw it working for a while, before failing consistently.
Environment
libzmq3-dev is already the newest version (4.2.5-1ubuntu0.2).
include
include
include
include
include
include
const char *zmq_path = "tcp://127.0.0.1:5555";
int main(int argc, char *argv) { int opt; int run_server = 0; void zmq_ctx = NULL; void *zmq_sck = NULL; char buf[10];
}
localadmin@remanava-dev-1:~/tools/zmq/c/client_server$ ./t -s Binding to server tcp://127.0.0.1:5555 Bound to server tcp://127.0.0.1:5555 Sleeping Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110) Aborted (core dumped) localadmin@remanava-dev-1:~/tools/zmq/c/client_server$
localadmin@remanava-dev-1:~/tools/zmq/c/client_server$ ./t connecting server tcp://127.0.0.1:5555 Connected to server tcp://127.0.0.1:5555 Sleeping Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110) Aborted (core dumped) localadmin@remanava-dev-1:~/tools/zmq/c/client_server$