Can the dealer socket created in the same class be used to send messages in other methods of the same class? If yes, then how is it supposed to be used? Example code:
private static class client_task implements Runnable
{
@Override
public void run()
{
ZContext ctx = new ZContext();
Socket client = ctx.createSocket(ZMQ.DEALER);
// Set random identity to make tracing easier
String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
client.setIdentity(identity.getBytes(ZMQ.CHARSET));
client.connect("tcp://localhost:5570");
Poller poller = ctx.createPoller(1);
poller.register(client, Poller.POLLIN);
int requestNbr = 0;
while (!Thread.currentThread().isInterrupted()) {
// Tick once per second, pulling in arriving messages
for (int centitick = 0; centitick < 100; centitick++) {
poller.poll(10);
if (poller.pollin(0)) {
ZMsg msg = ZMsg.recvMsg(client);
msg.getLast().print(identity);
msg.destroy();
}
}
client.send(String.format("request #%d", ++requestNbr), 0);
}
ctx.close();
}
}
So, I want to use this client.send(String.format("request #%d", ++requestNbr), 0);
in other methods within same class.