// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import org.zeromq.SocketType;
import org.zeromq.ZMQ;
import org.zeromq.ZContext;

public class Cli4
{
    private static final String TOPIC = "1234";
    private static void test(String addr) {
        try (ZContext ctx = new ZContext()) {
            ZMQ.Socket s = ctx.createSocket(SocketType.SUB);
            s.connect(addr);
            s.subscribe(TOPIC);
            int n = 0;
            while(n < 3) {
                String respmsg = s.recvStr();
                respmsg = respmsg.substring(TOPIC.length() + 1);
                System.out.println("Java client : " + respmsg);
                n++;
            }
            s.close();
        }
    }
    public static void main(String[] args) throws Exception
    {
        test("tcp://localhost:10001");
        test("tcp://localhost:10002");
        test("tcp://localhost:10003");
        test("tcp://localhost:10004");
        test("tcp://localhost:10005");
        test("tcp://localhost:10006");
    }
}
