Mercurial > hg > RemoteEditor > REPSessionManager
changeset 49:f8b4101746d2
UTF-8 Pack Method packUConv()/unpackUConv() add
author | fuchita |
---|---|
date | Tue, 13 Nov 2007 18:53:51 +0900 |
parents | b4991de8e83a |
children | 6f23795f61c9 |
files | rep/REPPacketReceive.java rep/REPPacketSend.java |
diffstat | 2 files changed, 61 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPPacketReceive.java Tue Nov 13 18:53:24 2007 +0900 +++ b/rep/REPPacketReceive.java Tue Nov 13 18:53:51 2007 +0900 @@ -28,6 +28,64 @@ //key.cancel(); } + public REPCommand unpack() { + + ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE); + long len = 0; + header.clear(); + try { + len = socketchannel.read(header); + if(len == -1){ + if(key != null){ + key.cancel(); + } + socketchannel.close(); + return null; + }else if(len == 0){ + return null; + } + } catch (IOException e1) { + e1.printStackTrace(); + } // limit = read length + if (len !=HEADER_SIZE) { + System.out.println("てす"); + // this can't happen + } + header.rewind(); // position = 0 + + String text = ""; + int cmd = header.getInt(); + int sid = header.getInt(); + int eid = header.getInt(); + int seqid = header.getInt(); + int lineno = header.getInt(); + int textsiz = header.getInt()/2; + + ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2); + + try { + len = socketchannel.read(textBuffer); + } catch (IOException e1) { + e1.printStackTrace(); + } // limit = read length + if (len != textsiz * 2) { + // this can't happen + System.out.println("あと"); + } + textBuffer.rewind(); + for(int i=0;i<textsiz;i++) { + text +=textBuffer.getChar(); + } + String string = text; + //System.out.println(string); + //getSocket(string); + REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); + System.out.println("received command: " + repcommand.toString()); + //getSocket(repcommand); + //System.out.println("received command: " + repcommand.toString()); + return repcommand; + } + public REPCommand unpackUConv() { ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE); long len = 0; @@ -103,70 +161,9 @@ REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); System.out.println("UnPack Packet: => cmd:"+cmd+" sid:"+sid+" eid:"+eid+"seqid:"+seqid+" lineno:"+lineno+" textsiz:" +textsiz+" text: "+string); System.out.println("received command: " + repcommand.toString()); - + return repcommand; } - - - - public REPCommand unpack() { - - ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE); - long len = 0; - header.clear(); - try { - len = socketchannel.read(header); - if(len == -1){ - if(key != null){ - key.cancel(); - } - socketchannel.close(); - return null; - }else if(len == 0){ - return null; - } - } catch (IOException e1) { - e1.printStackTrace(); - } // limit = read length - if (len !=HEADER_SIZE) { - System.out.println("てす"); - // this can't happen - } - header.rewind(); // position = 0 - - String text = ""; - int cmd = header.getInt(); - int sid = header.getInt(); - int eid = header.getInt(); - int seqid = header.getInt(); - int lineno = header.getInt(); - int textsiz = header.getInt()/2; - - ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2); - - try { - len = socketchannel.read(textBuffer); - } catch (IOException e1) { - e1.printStackTrace(); - } // limit = read length - if (len != textsiz * 2) { - // this can't happen - System.out.println("あと"); - } - textBuffer.rewind(); - for(int i=0;i<textsiz;i++) { - text +=textBuffer.getChar(); - } - String string = text; - //System.out.println(string); - //getSocket(string); - REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); - System.out.println("received command: " + repcommand.toString()); - //getSocket(repcommand); - //System.out.println("received command: " + repcommand.toString()); - return repcommand; - } - private void getSocket(REPCommand command) { if(command.cmd != REP.SMCMD_JOIN){
--- a/rep/REPPacketSend.java Tue Nov 13 18:53:24 2007 +0900 +++ b/rep/REPPacketSend.java Tue Nov 13 18:53:51 2007 +0900 @@ -67,7 +67,8 @@ public void send(REPCommand command){ try { - socketchannel.write(packUConv(command)); + socketchannel.write(pack(command)); + //socketchannel.write(packUConv(command)); //System.out.println(command.toString()); } catch (IOException e) { e.printStackTrace();