[zeromq-dev] help

Joshua Foster jhawk28 at gmail.com
Thu Apr 12 14:38:37 CEST 2012


I would recommend reading the guide. You will want to start out just using PUSH/PULL, REQ/REP, and PUB/SUB for learning ZeroMQ. Dealer and Router sockets are a little more advanced (and have their place). It looks like you have the back half to a work queue (rrbroker is the work distributer and the rrclient are the workers). You don't have the router front end with the actual clients. (http://zguide.zeromq.org/page:all#A-Request-Reply-Broker)

Joshua

On Apr 12, 2012, at 5:46 AM, daiweixing wrote:

> I am new to ZeroMQ, I have following codes:
> Dealer is following:
> public class rrbroker {
>     public static void main (String[] args) {
>         //  Prepare our context and sockets
>         Context context = ZMQ.context(1);
>  
>         Socket backend  = context.socket(ZMQ.DEALER);
>         backend.bind("tcp://*:5560");
>  
>         System.out.println("launch and connect broker.");
>  
>  
>         boolean more = false;
>         byte[] message;
>  
>         //  Switch messages between sockets
>         while (!Thread.currentThread().isInterrupted()) {            
>             //  poll and memorize multipart detection
>  
>             {
>                 while (true) {
>                     // receive message
>                     backend.send(message, more ? ZMQ.SNDMORE : 0);
>                     if(!more){
>                         break;
>                     }
>                 }
>             }
>         }
>         //  We never get here but clean up anyhow
>         backend.close();
>         context.term();
>     }
> }
>  
> Client is following:
> public class rrclient {
>     public static void main(String[] args) throws InterruptedException {
>        Context context = ZMQ.context(1);
>  
>        // Socket to talk to server
>        Socket requester = context.socket(ZMQ.REP);
>        requester.bind("tcp://*:5560");
> //     requester.connect("tcp://localhost:5560");
>  
>        System.out.println("launch and connect client.");
>  
>        for (int request_nbr = 0; request_nbr < 1000; request_nbr++) {
>            System.out.println("ssssssssssss");
>            byte[] reply = requester.recv(0);
>        }
>  
>        // We never get here but clean up anyhow
>        requester.close();
>        context.term();
>     }
>  
> Above can not work, what’s the matter? Who can help me?
>  
> Thanks a lot!
>  
> daiweixing
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120412/d161d4c9/attachment.htm>


More information about the zeromq-dev mailing list