This is the client side code that I use to communicate with the server: private byte[] getByte(final String table, final String name, final int doc_off, final int doc_len, final int comp_off, final int comp_len, final char compressionType) throws Exception { File file = new File(cacheRoot, table.substring(0, 3) + "/DOC/" + name); //$NON-NLS-1$ Context ctx = ZMQ.context(1); Socket req = ctx.socket(ZMQ.REQ); req.connect(ENDPOINT); // TODO Crear POJO en vez de Map Map<String, String> params = new HashMap<String, String>(); params.put("path", file.getAbsolutePath()); params.put("dOff", String.valueOf(doc_off)); params.put("dLen", String.valueOf(doc_len)); params.put("cOff", String.valueOf(comp_off)); params.put("clen", String.valueOf(comp_len)); params.put("cType", String.valueOf(compressionType)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(params); oos.close(); params.clear(); baos.close(); req.send(baos.toByteArray(), NO_FLAGS); byte[] data = ""> req.close(); ctx.term(); return data; } And on the server side I use the three attached classes public void run() { // Prepare our context and sockets Context context = ZMQ.context(1); Socket frontend = context.socket(ZMQ.ROUTER); Socket backend = context.socket(ZMQ.DEALER); frontend.bind("tcp://*:5559"); Thread threads[] = new Thread[workers]; for (int i = 0; i < threads.length; i++) { threads[i] = new WorkerThread(i, context); threads[i].start(); } System.out.println("launch and connect broker."); // Initialize poll set Poller items = context.poller(2); items.register(frontend, Poller.POLLIN); items.register(backend, Poller.POLLIN); boolean more = false; byte[] message; // Switch messages between sockets try { while (!Thread.currentThread().isInterrupted()) { // poll and memorize multipart detection items.poll(); if (items.pollin(0)) { while (true) { // receive message message = frontend.recv(0); more = frontend.hasReceiveMore(); // Broker it backend.send(message, more ? ZMQ.SNDMORE : 0); if (!more) { break; } } } if (items.pollin(1)) { while (true) { // receive message message = backend.recv(0); more = backend.hasReceiveMore(); // Broker it frontend.send(message, more ? ZMQ.SNDMORE : 0); if (!more) { break; } } } } } finally { // We never get here but clean up anyhow frontend.close(); backend.close(); context.term(); } } Does that help solving the problem?
El 05-03-2013, a las 18:19, Pieter Hintjens <p...@imatix.com> escribió:
|
ObjetoRemoto.java
Description: Binary data
Server.java
Description: Binary data
WorkerThread.java
Description: Binary data
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev