0

I have a program written in Java that should send messages out via ZeroMQ to be listened and responded to by another program I have running.

The problem is that the listener is on another computer on the local network and I need to somehow perform port forwarding in ZeroMQ in order for the messages to be received across the network.

    ZMQ.Context context = ZMQ.context(1);
    ZMQ.Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://192.168.78.14:5570"); //192.168.78.14 is the address of listening machine

    String msg = "Message";
    requester.send(msg.getBytes());

    byte[] reply = requester.recv();

When the above code is run, the program waits indefinitely for a response (that never comes) and so effectively is unresponsive. The listener is listening on tcp://127.0.0.1:5570 for messages. Setting it to tcp://0.0.0.0:5570 or tcp://*:5570 which supposedly opens listening to all addresses on given port also yields nothing.

Any help is appreciated.

user3666197
  • 1
  • 6
  • 50
  • 92
Shiri
  • 1,972
  • 7
  • 24
  • 46

1 Answers1

1

This solution is being used in production for about the last two decades already, as large groups of spatially distributed Virtual Machines need to get similar host:port sessions live, independently of their actual instantiation in the respective real network address spaces


Use ssh-port-forwarding tunnels between the hosts

The solution is in principle independent of the ZeroMQ framework setup.

Setup a live SSH-connection between two hosts of your wish.

On each end, provide the respective port-forwarding mappings, according to the port#-s used in ZeroMQ communication setup.

On host A 192.168.78.14 forward local port 5570 to a remote IP:port# target

L5570 forward to 192.168.78.15:5570

On host A a ZeroMQ-communicating pattern transparently "speaks" to local port 5570, which is by the service of the ssh-tunnel forwarded to the opposite side, host B and delivered to there referred port 5570 for further socket-traffic processing.

On host B 192.168.78.15 a ZeroMQ-communicating pattern seamlessly "interacts" through the port 5570, as if the communicating counterparty was "sitting" in the same "box", and processes the socket-traffic delivered actually through the ssh-tunnel, without knowing about such trick.

QED.


For one's faster and easier prototyping, one might opt to use rather .socket(ZMQ.PAIR) archetype, which does not introduce any high-level ZeroMQ-behavioural pattern and simply sends whatever the socket interface is instructed to send to the opposite side ( without any waiting for REP-reply to prior REQ-message )

user3666197
  • 1
  • 6
  • 50
  • 92