Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/REPPacketReceive.java @ 46:4fdeeb2d5645
UTF-8 Pack Method PackUConv() add
author | fuchita |
---|---|
date | Tue, 13 Nov 2007 17:35:43 +0900 |
parents | 1b05995d3118 |
children | f8b4101746d2 |
comparison
equal
deleted
inserted
replaced
45:10f1adf6d74d | 46:4fdeeb2d5645 |
---|---|
55 int cmd = header.getInt(); | 55 int cmd = header.getInt(); |
56 int sid = header.getInt(); | 56 int sid = header.getInt(); |
57 int eid = header.getInt(); | 57 int eid = header.getInt(); |
58 int seqid = header.getInt(); | 58 int seqid = header.getInt(); |
59 int lineno = header.getInt(); | 59 int lineno = header.getInt(); |
60 int textsiz = header.getInt()/5; | 60 int textsiz = header.getInt(); |
61 //int tmptextsiz = header.getInt(); | |
62 //int textsiz = (tmptextsiz /5) + (tmptextsiz % 5); | |
61 | 63 |
62 ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*5); | 64 ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz); |
63 | 65 |
64 try { | 66 try { |
65 len = socketchannel.read(textBuffer); | 67 len = socketchannel.read(textBuffer); |
68 if(len == -1){ | |
69 if(key != null){ | |
70 key.cancel(); | |
71 } | |
72 socketchannel.close(); | |
73 return null; | |
74 }else if(len == 0){ | |
75 return null; | |
76 } | |
66 } catch (IOException e1) { | 77 } catch (IOException e1) { |
67 e1.printStackTrace(); | 78 e1.printStackTrace(); |
68 } // limit = read length | 79 } // limit = read length |
69 if (len != textsiz * 5) { | 80 if (len != textsiz) { |
70 // this can't happen | 81 // this can't happen |
71 System.out.println("‚ ‚Æ"); | 82 System.out.println("‚ ‚Æ"); |
72 } | 83 } |
73 textBuffer.rewind(); | 84 textBuffer.rewind(); |
74 | 85 |
79 try { | 90 try { |
80 cb = decoder.decode(textBuffer); | 91 cb = decoder.decode(textBuffer); |
81 } catch (CharacterCodingException e) { | 92 } catch (CharacterCodingException e) { |
82 e.printStackTrace(); | 93 e.printStackTrace(); |
83 } | 94 } |
95 cb.rewind(); | |
84 | 96 |
85 String string = cb.toString(); | 97 String string = cb.toString(); |
86 | 98 |
87 //System.out.println("textsize: " +textsiz); | 99 //System.out.println("textsize: " +textsiz); |
88 //System.out.println("CharBuffer size: " +cb.length()); | 100 //System.out.println("CharBuffer size: " +cb.length()); |
89 //System.out.println(cb.toString()); | 101 //System.out.println(cb.toString()); |
90 | 102 |
91 REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); | 103 REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); |
104 System.out.println("UnPack Packet: => cmd:"+cmd+" sid:"+sid+" eid:"+eid+"seqid:"+seqid+" lineno:"+lineno+" textsiz:" +textsiz+" text: "+string); | |
92 System.out.println("received command: " + repcommand.toString()); | 105 System.out.println("received command: " + repcommand.toString()); |
93 | 106 |
94 return repcommand; | 107 return repcommand; |
95 } | 108 } |
96 | 109 |