Skip to content

Commit

Permalink
#1 playing with base socket pair
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Jul 22, 2016
1 parent cbf26d0 commit b8d0abf
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
*
*/
package org.irods.jargon2.provider.zeromq.sandbox;

import org.zeromq.ZMQ;

/**
* Test simple socket provider for zeromq
* @author mconway
*
*/
public class ZeromqProvider {


public static void main(String[] args) {
ZMQ.Context context = ZMQ.context(1);

// Socket to talk to server
System.out.println("Connecting to hello world server…");

ZMQ.Socket requester = context.socket(ZMQ.REQ);
requester.connect("tcp://localhost:5555");

for (int requestNbr = 0; requestNbr != 10; requestNbr++) {
String request = "Hello";
System.out.println("Sending Hello " + requestNbr);
requester.send(request.getBytes(), 0);

byte[] reply = requester.recv(0);
System.out.println("Received " + new String(reply) + " " + requestNbr);
}
requester.close();
context.term();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

/**
* throw away sandbox to start playing with zeromq
* @author mconway
*
*/
package org.irods.jargon2.provider.zeromq.sandbox;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
*/
package org.irods.jargon2.provider.zeromq.sandbox.server;

import org.zeromq.ZMQ;

/**
* Simple server side of straight-ahead zeromq point to point socket
* @author mconway
*
*/
public class ZeromqServer {

public static void main(String[] args) throws Exception {
ZMQ.Context context = ZMQ.context(1);

// Socket to talk to clients
ZMQ.Socket responder = context.socket(ZMQ.REP);
responder.bind("tcp://*:5555");

while (!Thread.currentThread().isInterrupted()) {
// Wait for next request from the client
byte[] request = responder.recv(0);
System.out.println("Received Hello");

// Do some 'work'
Thread.sleep(1000);

// Send reply back to client
String reply = "World";
responder.send(reply.getBytes(), 0);
}
responder.close();
context.term();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Play sandbox for server side of zeromq
* @author mconway
*
*/
package org.irods.jargon2.provider.zeromq.sandbox.server;

0 comments on commit b8d0abf

Please sign in to comment.