# HG changeset patch # User pin # Date 1161516990 -32400 # Node ID ff7e7833cdedd3372dd734dd51bc7626323eb25b # Parent bf97ccde466d3e285c3295d653c91c03f1512afb pack/ unpack with putInt/getInt and ByteBuffer diff -r bf97ccde466d -r ff7e7833cded src/remoteeditor/network/REP.java --- a/src/remoteeditor/network/REP.java Sun Oct 22 19:06:59 2006 +0900 +++ b/src/remoteeditor/network/REP.java Sun Oct 22 20:36:30 2006 +0900 @@ -21,19 +21,19 @@ int seqid; int textsiz; - byte REP_INSERT_CMD = 6; - byte REP_INSERT_ACK_CMD = 7; - byte REP_JOIN_CMD = 41; - byte REP_JOIN_ACK_CMD = 42; - byte REP_PUT_CMD = 45; - byte REP_PUT_ACK_CMD = 46; - byte REP_SELECT_CMD = 47; - byte REP_SELECT_ACK_CMD = 48; - byte REP_QUIT_CMD = 53; - byte REP_QUIT_ACK_CMD = 54; + static final int REP_INSERT_CMD = 6; + static final int REP_INSERT_ACK_CMD = 7; + static final int REP_JOIN_CMD = 41; + static final int REP_JOIN_ACK_CMD = 42; + static final int REP_PUT_CMD = 45; + static final int REP_PUT_ACK_CMD = 46; + static final int REP_SELECT_CMD = 47; + static final int REP_SELECT_ACK_CMD = 48; + static final int REP_QUIT_CMD = 53; + static final int REP_QUIT_ACK_CMD = 54; ByteBuffer buffer = ByteBuffer.allocateDirect(1024); - byte[] readbyte = new byte[1024]; + ByteBuffer read_buffer = ByteBuffer.allocateDirect(1024); String string; private RSocketListener socketListener; @@ -84,19 +84,19 @@ public void join() throws IOException{ sc.write(pack(buffer, REP_JOIN_CMD, sid, eid, seqid, lineno, "afro")); - unpack(buffer); + unpack(read_buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } public void put() throws Exception { sc.write(pack(buffer, REP_PUT_CMD, sid, eid, seqid, lineno, "filename")); - unpack(buffer); + unpack(read_buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } public void select() throws Exception { sc.write(pack(buffer, REP_SELECT_CMD, sid, eid, seqid, lineno, "afro")); - unpack(buffer); + unpack(read_buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } @@ -111,96 +111,56 @@ //System.out.println("pack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno); - + //ByteBuffer buffer = ByteBuffer.allocateDirect(24+textsiz); - + buffer.clear(); // position = 0 buffer.putInt(cmd); buffer.putInt(sid); buffer.putInt(eid); buffer.putInt(seqid); buffer.putInt(lineno); - buffer.putInt(text.length()); + buffer.putInt(text.length()*2); //buffer.putString(text); + System.out.println("pack:" + cmd +", "+ "length="+ text.length() +" "+ sid +", "+ eid +", "+ seqid +", "+ lineno); for(int i=0;i