[zeromq-dev] Timeout REQ-REP

Bachmair Florian - flexSolution GmbH florian.bachmair at flexsolution.eu
Tue Mar 15 08:43:33 CET 2016


Is there a way to get a Timeout for a Request?
If I send a Request, it "hangs" till the other side Responses. If the 
other Side is not up, I never get a response.
I would like to detect this on the Request side. Is that possible?

my current request code is:

JNIEXPORT jstring JNICALL core_JNI_1zeromq_request(
         JNIEnv *env, jobject object, jstring address, jstring timestamp,
         jstring sender, jstring command, jstring message) {
     const char* addr = (*env)->GetStringUTFChars(env, address, 0);
     const char* ts = (*env)->GetStringUTFChars(env, timestamp, 0);
     const char* s = (*env)->GetStringUTFChars(env, sender, 0);
     const char* cmd = (*env)->GetStringUTFChars(env, command, 0);
     const char* msg = (*env)->GetStringUTFChars(env, message, 0);

     void *req = zsocket_new(context, ZMQ_REQ);
     int rc = zsocket_connect(req, "%s", addr);

     assert(rc == 0);
     s_sendmore(req, ts);
     s_sendmore(req, s);
     s_sendmore(req, cmd);
     s_send(req, msg);

     char* reply = zstr_recv(req);

     zsocket_destroy(context, req);

     (*env)->ReleaseStringUTFChars(env, timestamp, ts);
     (*env)->ReleaseStringUTFChars(env, sender, s);
     (*env)->ReleaseStringUTFChars(env, message, msg);

     jstring ret = (*env)->NewStringUTF(env, reply);
     return ret;

Thank you

More information about the zeromq-dev mailing list