[zeromq-dev] IPC communication between C and JAVA application

Federico Serale federico.serale at gmail.com
Sun Jan 27 16:04:04 CET 2013

i'm on a ubuntu OS and i am trying to make a communication between C 
and  JAVA with IPC.

i created a server In C, and this is the code:

    #include "testutil.hpp"
    #include <stdio.h>

    int main () {
         void *ctx = zmq_init (1);
         assert (ctx);

         void *sb = zmq_socket (ctx, ZMQ_REP);
         assert (sb);
         int rc = zmq_bind (sb, "ipc:///tmp/test");
         assert (rc == 0);

         /* Create an empty ØMQ message */
         zmq_msg_t msg;
         rc = zmq_msg_init (&msg);
         assert (rc == 0);

         /* Block until a message is available to be received from socket */
         rc = zmq_recv (sb, &msg, 0, 0);
         assert (rc == 0);
         printf("%s", msg);
         /* Release message */ zmq_msg_close (&msg);

         rc = zmq_close (sb);
         assert (rc == 0);

         rc = zmq_term (ctx);
         assert (rc == 0);
         return 0;

and i created a client in JAVA, this is the code:

    import org.zeromq.ZMQ;

    public class Main{
         public static void main(String[] args){
             //  Prepare our context and socket
             ZMQ.Context context = ZMQ.context(1);
             ZMQ.Socket socket = context.socket(ZMQ.REQ);

             System.out.println("Connecting to hello world server...");
             socket.connect ("ipc:///tmp/test");

             String requestString = "Hello\n";
             byte[] request = requestString.getBytes();
             request[request.length-1]=0; //Sets the last byte to 0
             // Send the message
             socket.send(request, 0);


The client application seems that ends successfully, while the server 
application is blocked waiting for reception of a message. What could be 
the problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130127/3ac561fe/attachment.htm>

More information about the zeromq-dev mailing list