首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

ZeroMQ之REP/REQ形式

2012-08-03 
ZeroMQ之REP/REQ模式package reqrepimport org.zeromq.ZMQpublic class REP {/*** @param args* @throws

ZeroMQ之REP/REQ模式

package reqrep;import org.zeromq.ZMQ;public class REP { /** * @param args * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException {// TODO Auto-generated method stubZMQ.Context context = ZMQ.context(1);ZMQ.Socket s = context.socket(ZMQ.REP);s.bind("tcp://*:5557");int i = 0;while (true) { i++; String msg = new String(s.recv(0)); s.send((msg + "_rep"+i).getBytes(), 0);} }}

package reqrep;import org.zeromq.ZMQ;public class REQ { /** * @param args * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException {// TODO Auto-generated method stubZMQ.Context context = ZMQ.context(1);ZMQ.Socket s = context.socket(ZMQ.REQ);s.connect("tcp://*:5557");int i = 0;while (true) { Thread.currentThread().sleep(2000); s.send(("msg" + "_req").getBytes(), 0); String rev = new String(s.recv(0)); System.out.println(rev);} }}

msg_req_rep1msg_req_rep2msg_req_rep3msg_req_rep4msg_req_rep5msg_req_rep6msg_req_rep7msg_req_rep8...

?

显然这种应答模式的效率很低!

热点排行