【问题标题】:zmq_unbind fails in Czmq_unbind 在 C 中失败
【发布时间】:2019-09-07 21:52:28
【问题描述】:

我在 C 中使用 ØMQ,我注意到在调用 zmq_unbind 时它返回 -1。我的 ØMQ 版本是 4.2.2。这是一个失败的简单代码:

#include <stdio.h>
#include <stdlib.h>
#include "zmq.h"

#define SERVER_ENDPOINT "tcp://*:5555"

int main(void)
{
  void *context = zmq_ctx_new();
  void *socket = zmq_socket(context, ZMQ_REP);
  int rc = zmq_bind(socket, SERVER_ENDPOINT);
  if (rc) {
    fprintf(stderr, "Error: could not bind the socket.\n");
    exit(1);
  }

  rc = zmq_unbind(socket, SERVER_ENDPOINT);
  if (rc) {
    fprintf(stderr, "Error: could not unbind the socket.\n");
    exit(1);
  }
  rc = zmq_close(socket);
  if (rc) {
    fprintf(stderr, "Error: could not close the socket.\n");
    exit(1);
  }

  zmq_ctx_destroy(context);

  return 0;
}

【问题讨论】:

  • 你能检查一下errno吗?
  • @EnricoDetoma printf("%d - %s\n", rc, zmq_strerror(errno)); 返回“-1 - 没有这样的文件或目录”。

标签: c zeromq


【解决方案1】:

带有通配符的 tcp://*:5555 不是 zmq_unbind 的有效选项。

这里建议:https://github.com/zeromq/pyzmq/issues/1025

last_endpoint 套接字选项可用于检索实际的 使用通配符时的端点

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多