Mercurial > hg > RemoteEditor > Eclipse
diff src/remoteeditor/network/REP.java @ 8:bf97ccde466d
*** empty log message ***
author | fuchita |
---|---|
date | Sun, 22 Oct 2006 19:06:59 +0900 |
parents | c5c8358a14f3 |
children | ff7e7833cded |
line wrap: on
line diff
--- a/src/remoteeditor/network/REP.java Sun Oct 22 18:05:10 2006 +0900 +++ b/src/remoteeditor/network/REP.java Sun Oct 22 19:06:59 2006 +0900 @@ -14,12 +14,12 @@ public class REP implements Runnable{ SocketChannel sc; - private byte cmd; - private byte eid; - private byte lineno; - private byte sid; - private byte seqid; - private byte textsiz; + int cmd; + int eid; + int lineno; + int sid; + int seqid; + int textsiz; byte REP_INSERT_CMD = 6; byte REP_INSERT_ACK_CMD = 7; @@ -72,7 +72,7 @@ put(); } - dialog = new InputDialog(shell, "repselect", "read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string, Byte.toString(sid), null); + dialog = new InputDialog(shell, "repselect", "read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string ,Integer.toString(sid), null); if(dialog.open() == Window.OK){ try { sid = (byte) Integer.parseInt(dialog.getValue()); @@ -83,31 +83,77 @@ } public void join() throws IOException{ - sc.write(pack(REP_JOIN_CMD, sid, eid, seqid, lineno, "afro")); - unpack(); + sc.write(pack(buffer, REP_JOIN_CMD, sid, eid, seqid, lineno, "afro")); + unpack(buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } public void put() throws Exception { - sc.write(pack(REP_PUT_CMD, sid, eid, seqid, lineno, "filename")); - unpack(); + sc.write(pack(buffer, REP_PUT_CMD, sid, eid, seqid, lineno, "filename")); + unpack(buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } public void select() throws Exception { - sc.write(pack(REP_SELECT_CMD, sid, eid, seqid, lineno, "afro")); - unpack(); + sc.write(pack(buffer, REP_SELECT_CMD, sid, eid, seqid, lineno, "afro")); + unpack(buffer); System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } public void insert(int offset, int length, String text) throws IOException { seqid = (byte)offset; - sc.write(pack(REP_INSERT_CMD, sid, eid, seqid, lineno, text)); + sc.write(pack(buffer, REP_INSERT_CMD, sid, eid, seqid, lineno, text)); //unpack(); //System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string); } - public ByteBuffer pack(byte REP_CMD, byte sid, byte eid, byte seqid, byte lineno, String text) { + public ByteBuffer pack(ByteBuffer buffer,int cmd, int sid, int eid, int seqid, int lineno, String text ) { + + + //System.out.println("pack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno); + + //ByteBuffer buffer = ByteBuffer.allocateDirect(24+textsiz); + + buffer.putInt(cmd); buffer.putInt(sid); buffer.putInt(eid); + buffer.putInt(seqid); buffer.putInt(lineno); + buffer.putInt(text.length()); + //buffer.putString(text); + + for(int i=0;i<text.length();i++) { + buffer.putChar(text.charAt(i)); + } + System.out.println("pack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno); + + return buffer; + } + + +/* public void unpack() { + int cmd, sid, eid, seqid, lineno; String text = ""; + int textsiz = 0; + + buffer.rewind(); + + cmd = buffer.getInt(); sid = buffer.getInt(); eid = buffer.getInt(); + seqid = buffer.getInt(); lineno = buffer.getInt(); textsiz = buffer.getInt(); + + + for(int i=0;i<textsiz;i++) { + text +=buffer.getChar(); + } + + System.out.println("unpack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +"," + text); + //byte[] readbyte = new byte[textsiz]; + //for(int i = 0; i < textsiz; i++){ + //readbyte[i] = buffer.get(); + //System.out.println(readbyte[i]); + //} + //text = new String(readbyte, 0, textsiz); + + } + + +*/ /*public ByteBuffer pack(byte REP_CMD, byte sid, byte eid, byte seqid, byte lineno, String text) { byte[] REP_PACK = new byte[24]; REP_PACK = new byte[24+text.length()]; REP_PACK[3] = REP_CMD; @@ -133,27 +179,33 @@ * */ - return buffer; - } + /* return buffer; + }*/ - public void unpack() throws IOException{ + public void unpack(ByteBuffer buffer) throws IOException{ buffer.clear(); sc.read(buffer); - buffer.flip(); - for(int i = 0; i < 24; i++){ + buffer.rewind(); + /*for(int i = 0; i < 24; i++){ readbyte[i] = buffer.get(); //System.out.println(readbyte[i]); + }*/ + String text = ""; + cmd = buffer.getInt(); + sid = buffer.getInt(); + eid = buffer.getInt(); + seqid = buffer.getInt(); + lineno = buffer.getInt(); + textsiz = buffer.getInt(); + for(int i=0;i<textsiz;i++) { + text +=buffer.getChar(); } - cmd = readbyte[3]; - sid = readbyte[7]; - eid = readbyte[11]; - seqid = readbyte[15]; - lineno = readbyte[19]; - textsiz = readbyte[23]; - for(int i = 0; i < textsiz; i++){ + + /*for(int i = 0; i < textsiz; i++){ readbyte[i] = buffer.get(); } - string = new String(readbyte, 0, textsiz); + string = new String(readbyte, 0, textsiz);*/ + string = text; } public void addSocketListener(RSocketListener socketListener){ @@ -189,7 +241,7 @@ //} //string = new String(readbyte, 0, textsiz); try { - unpack(); + unpack(buffer); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();