jeromq icon indicating copy to clipboard operation
jeromq copied to clipboard

Can we figure out the endpoint name given a zeromq socket variable?

Open fjamal21 opened this issue 6 years ago • 4 comments

If I have a ZeroMQ socket variable like this:

final Socket socket = getSocket();

Then can I figure out what endpoint or machine I have in that socket variable? I want to print out the endpoint name basically. I tried looking up the SocketBase class but couldn't figured it out.

This is the way I make Socket:

  private Set<Socket> connect(final List<String> addresses, final int socketType) {
    Set<Socket> sockets = new HashSet<>();
    for (String address : addresses) {
      Socket socket = ctx.createSocket(socketType);
      String identity = String.format("%04X-%04X", random.nextInt(), random.nextInt());
      socket.setIdentity(identity.getBytes(ZMQ.CHARSET));
      socket.setTCPKeepAlive(1);
      socket.setSendTimeOut(1);
      socket.setLinger(2);
      socket.connect(address);
      sockets.add(socket);
    }
    return sockets;
  }

fjamal21 avatar Dec 23 '17 22:12 fjamal21

If you are looking for local endpoints, please have a look on the ZMonitor:

https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/ZMonitorTest.java

or more low-level:

https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/TestEvents.java

fredoboulo avatar Dec 29 '17 11:12 fredoboulo

What I meant was - If I have a Socket variable, then can I figure out what endpoint was used to make that Socket variable? All my endpoints are like this:

tcp://lmachineA:portNumber

I checked those two classes but can't see how to figure out how to extract endpoint given a socket variable unless I have missed something?

fjamal21 avatar Jan 02 '18 20:01 fjamal21

There seems to be a misunderstanding. In which way are they different from the addresses your code is supplying for the connect operation?

fredoboulo avatar Jan 03 '18 18:01 fredoboulo

@fjamal21 Be aware that a socket may be connected to multiple endpoints in general. If there were a function to query this, it would need to return a list of endpoints.

sigiesec avatar Jan 08 '18 10:01 sigiesec