[zeromq-dev] help

William Brown william.brown at ericsson.com
Thu Apr 12 14:35:19 CEST 2012


    Daiweixing,

  - Use a valid IP address in your URL
  - Call bind only on the server side.
    - Use the connect method on the client to "connect" to the bound server
  - Use ZMQ.REQ in the server instead of ZMQ.DEALER.
    - Your server is not actually sending anything.
        Move the for loop from the client into the server.
        Add data to the payload before you call the send function
  - Move your while loop into your client from the server and block on the recv call.

    --Corey
________________________________
From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-bounces at lists.zeromq.org] On Behalf Of daiweixing
Sent: Thursday, April 12, 2012 5:46 AM
To: zeromq-dev at lists.zeromq.org
Subject: [zeromq-dev] help

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120412/fcce6ca1/attachment.htm>


More information about the zeromq-dev mailing list