annotate src/remoteeditor/network/REP.java @ 32:86e04721e463

*** empty log message ***
author pin
date Tue, 16 Jan 2007 18:10:02 +0900
parents ebbc14dd1a1a
children 96306e8dc217
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
1 package remoteeditor.network;
cf13bdba762b Initial revision
pin
parents:
diff changeset
2
cf13bdba762b Initial revision
pin
parents:
diff changeset
3 import java.io.IOException;
cf13bdba762b Initial revision
pin
parents:
diff changeset
4 import java.net.InetSocketAddress;
cf13bdba762b Initial revision
pin
parents:
diff changeset
5 import java.nio.ByteBuffer;
cf13bdba762b Initial revision
pin
parents:
diff changeset
6 import java.nio.channels.SocketChannel;
14
0ac009f1c69e *** empty log message ***
pin
parents: 10
diff changeset
7 import java.util.LinkedList;
0ac009f1c69e *** empty log message ***
pin
parents: 10
diff changeset
8 import java.util.List;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
9
cf13bdba762b Initial revision
pin
parents:
diff changeset
10 import org.eclipse.jface.dialogs.InputDialog;
cf13bdba762b Initial revision
pin
parents:
diff changeset
11 import org.eclipse.jface.window.Window;
cf13bdba762b Initial revision
pin
parents:
diff changeset
12 import org.eclipse.swt.widgets.Shell;
cf13bdba762b Initial revision
pin
parents:
diff changeset
13
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
14 import sample.merge.Rep_Cmd;
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
15 import sample.merge.Translate;
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
16
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
17
cf13bdba762b Initial revision
pin
parents:
diff changeset
18
cf13bdba762b Initial revision
pin
parents:
diff changeset
19 public class REP implements Runnable{
cf13bdba762b Initial revision
pin
parents:
diff changeset
20
cf13bdba762b Initial revision
pin
parents:
diff changeset
21 SocketChannel sc;
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
22 int cmd;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
23 int eid;
31
ebbc14dd1a1a *** empty log message ***
pin
parents: 30
diff changeset
24 int eid2;
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
25 int lineno;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
26 int sid;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
27 int seqid;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
28 int textsiz;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
29
15
535f124c2fc3 *** empty log message ***
pin
parents: 14
diff changeset
30 public static final int REP_INSERT_CMD = 6;
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
31 public static final int REP_INSERT_ACK_CMD = 7;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
32 public static final int REP_DELETE_CMD = 9;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
33 public static final int REP_DELETE_ACK_CMD = 10;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
34 public static final int REP_REPLACE_CMD = 13;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
35 public static final int REP_REPLACE_ACK_CMD = 14;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
36 public static final int REP_JOIN_CMD = 41;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
37 public static final int REP_JOIN_ACK_CMD = 42;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
38 public static final int REP_PUT_CMD = 45;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
39 public static final int REP_PUT_ACK_CMD = 46;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
40 public static final int REP_SELECT_CMD = 47;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
41 public static final int REP_SELECT_ACK_CMD = 48;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
42 public static final int REP_QUIT_CMD = 53;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
43 public static final int REP_QUIT_ACK_CMD = 54;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
44
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
45 static final int HEADER_SIZE = 24;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
46
cf13bdba762b Initial revision
pin
parents:
diff changeset
47 String string;
20
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
48 public RSocketListener socketListener;
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
49 Shell shell;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
50
20
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
51 List <Rep_Cmd> myCmdList = new LinkedList<Rep_Cmd>();
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
52 List <Rep_Cmd> othersCmdList = new LinkedList<Rep_Cmd>();
19
cc68a00f9850 *** empty log message ***
pin
parents: 18
diff changeset
53 private String filename;
14
0ac009f1c69e *** empty log message ***
pin
parents: 10
diff changeset
54
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
55 public REP() {
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
56 String host = "localhost";
20
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
57 int port = 8765;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
58
cf13bdba762b Initial revision
pin
parents:
diff changeset
59 InputDialog dialog = new InputDialog(shell, "REP", "host", "localhost", null);
cf13bdba762b Initial revision
pin
parents:
diff changeset
60 if(dialog.open() == Window.OK){
cf13bdba762b Initial revision
pin
parents:
diff changeset
61 host = dialog.getValue();
cf13bdba762b Initial revision
pin
parents:
diff changeset
62 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
63
20
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
64 dialog = new InputDialog(shell, "REP", "port", "8756", null);
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
65 if (dialog.open() == Window.OK) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
66 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
67 port = Integer.parseInt(dialog.getValue());
cf13bdba762b Initial revision
pin
parents:
diff changeset
68 } catch (NumberFormatException x) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
69 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
70 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
71
cf13bdba762b Initial revision
pin
parents:
diff changeset
72
cf13bdba762b Initial revision
pin
parents:
diff changeset
73 InetSocketAddress addr = new InetSocketAddress(host, port);
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
74 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
75 sc = SocketChannel.open();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
76
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
77 sc.configureBlocking(true);
cf13bdba762b Initial revision
pin
parents:
diff changeset
78 sc.connect(addr);
cf13bdba762b Initial revision
pin
parents:
diff changeset
79 while(!sc.finishConnect()){
cf13bdba762b Initial revision
pin
parents:
diff changeset
80 System.out.println("afro");
cf13bdba762b Initial revision
pin
parents:
diff changeset
81 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
82 join();
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
83 } catch (IOException e) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
84 e.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
85 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
86
cf13bdba762b Initial revision
pin
parents:
diff changeset
87 dialog = new InputDialog(shell, "repput", "read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string, "hugo", null);
cf13bdba762b Initial revision
pin
parents:
diff changeset
88 if(dialog.open() == Window.OK){
19
cc68a00f9850 *** empty log message ***
pin
parents: 18
diff changeset
89 filename = dialog.getValue();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
90 put();
cf13bdba762b Initial revision
pin
parents:
diff changeset
91 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
92
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
93 dialog = new InputDialog(shell, "repselect", "read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string ,Integer.toString(sid), null);
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
94 if(dialog.open() == Window.OK){
cf13bdba762b Initial revision
pin
parents:
diff changeset
95 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
96 sid = (byte) Integer.parseInt(dialog.getValue());
cf13bdba762b Initial revision
pin
parents:
diff changeset
97 } catch (NumberFormatException x) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
98 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
99 select();
cf13bdba762b Initial revision
pin
parents:
diff changeset
100 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
101 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
102
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
103 public void join() {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
104 rWrite(pack( REP_JOIN_CMD, sid, eid, seqid, lineno, "afro"));
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
105 unpack();
31
ebbc14dd1a1a *** empty log message ***
pin
parents: 30
diff changeset
106 eid2 = eid;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
107 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
108 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
109
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
110 public void put() {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
111 rWrite(pack(REP_PUT_CMD, sid, eid, seqid, lineno, filename));
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
112 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
113 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
114 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
115
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
116 public void select() {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
117 rWrite(pack(REP_SELECT_CMD, sid, eid, seqid, lineno, "afro"));
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
118 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
119 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
120 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
121
24
e9b015eb1e05 *** empty log message ***
pin
parents: 21
diff changeset
122 /* public void insert(int offset, int length, String text) {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
123 cmd = REP_INSERT_CMD;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
124 seqid = (byte)offset;
20
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
125 try {
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
126 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
127 } catch (IOException e1) {
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
128 e1.printStackTrace();
e5472194938a *** empty log message ***
pin
parents: 19
diff changeset
129 }
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
130 try {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
131 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
132 System.out.println("myCmdList : " + myCmdList.toString());
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
133 } catch (Exception e) {
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
134 e.printStackTrace();
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
135 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
136 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
137
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
138 public void replace(int offset, int length, String text) throws IOException {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
139 cmd = REP_REPLACE_CMD;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
140 seqid = (byte)offset;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
141 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
142 try {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
143 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
144 System.out.println("myCmdList : " + myCmdList.toString());
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
145 } catch (Exception e) {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
146 e.printStackTrace();
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
147 }
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
148 }
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
149
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
150 public void delete(int offset, int length, String text) throws IOException {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
151 cmd = REP_DELETE_CMD;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
152 seqid = (byte)offset;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
153 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
154 try {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
155 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
156 System.out.println("myCmdList : " + myCmdList.toString());
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
157 } catch (Exception e) {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
158 e.printStackTrace();
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
159 }
24
e9b015eb1e05 *** empty log message ***
pin
parents: 21
diff changeset
160 }*/
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
161
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
162 public ByteBuffer pack(int cmd, int sid, int eid, int seqid, int lineno, String text ) {
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
163
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
164 ByteBuffer buffer = ByteBuffer.allocateDirect(24+text.length()*2);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
165 buffer.clear(); // position = 0
32
86e04721e463 *** empty log message ***
pin
parents: 31
diff changeset
166 buffer.putInt(cmd); buffer.putInt(sid); buffer.putInt(eid2);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
167 buffer.putInt(seqid); buffer.putInt(lineno);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
168 buffer.putInt(text.length()*2);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
169 //buffer.putString(text);
24
e9b015eb1e05 *** empty log message ***
pin
parents: 21
diff changeset
170 //System.out.println("pack:" + cmd +", "+ "length="+ text.length() +" "+ sid +", "+ eid +", "+ seqid +", "+ lineno);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
171
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
172 for(int i=0;i<text.length();i++) {
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
173 buffer.putChar(text.charAt(i));
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
174 }
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
175 buffer.flip(); // limit = current position, position = 0
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
176 return buffer;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
177 }
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
178
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
179 public void unpack() {
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
180 ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
181 long len = 0;
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
182 header.clear();
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
183 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
184 len = sc.read(header);
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
185 } catch (IOException e1) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
186 e1.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
187 } // limit = read length
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
188 if (len !=HEADER_SIZE) {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
189 System.out.println("‚Ä‚·");
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
190 // this can't happen
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
191 }
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
192 header.rewind(); // position = 0
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
193 /*for(int i = 0; i < 24; i++){
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
194 readbyte[i] = header.get();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
195 //System.out.println(readbyte[i]);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
196 }*/
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
197 String text = "";
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
198 cmd = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
199 sid = header.getInt();
31
ebbc14dd1a1a *** empty log message ***
pin
parents: 30
diff changeset
200 eid = header.getInt();
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
201 seqid = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
202 lineno = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
203 textsiz = header.getInt()/2;
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
204
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
205 ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2);
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
206 //buffer.limit(textsiz*2);
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
207 //buffer.rewind();
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
208 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
209 len = sc.read(textBuffer);
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
210 } catch (IOException e1) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
211 e1.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
212 } // limit = read length
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
213 if (len !=HEADER_SIZE) {
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
214 // this can't happen
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
215 }
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
216 textBuffer.rewind();
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
217 for(int i=0;i<textsiz;i++) {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
218 text +=textBuffer.getChar();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
219 }
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
220 string = text;
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
221 try {
29
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
222 if(eid2 != eid) othersCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, textsiz, text));
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
223 } catch (Exception e) {
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
224 e.printStackTrace();
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
225 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
226 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
227
cf13bdba762b Initial revision
pin
parents:
diff changeset
228 public void addSocketListener(RSocketListener socketListener){
cf13bdba762b Initial revision
pin
parents:
diff changeset
229 Thread th = new Thread(this);
cf13bdba762b Initial revision
pin
parents:
diff changeset
230 th.start();
cf13bdba762b Initial revision
pin
parents:
diff changeset
231 this.socketListener = socketListener;
cf13bdba762b Initial revision
pin
parents:
diff changeset
232 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
233
cf13bdba762b Initial revision
pin
parents:
diff changeset
234 public void run() {
cf13bdba762b Initial revision
pin
parents:
diff changeset
235 while(sc.isConnected()){
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
236 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
237 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
29
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
238 for(Rep_Cmd othersCmd:othersCmdList){
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
239 socketListener.packetReceived(new RSocketEvent(othersCmd.cmd, othersCmd.sid, othersCmd.eid, othersCmd.seq, othersCmd.lineno, othersCmd.string.length(), othersCmd.string));
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
240 othersCmdList.remove(othersCmd);
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
241 }
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
242 //socketListener.packetReceived(new RSocketEvent(cmd, sid, eid, seqid, lineno, textsiz, string)); //
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
243 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
244
cf13bdba762b Initial revision
pin
parents:
diff changeset
245 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
246 public void rRead(ByteBuffer buffer){
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
247 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
248 sc.read(buffer);
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
249 } catch (IOException e) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
250 e.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
251 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
252 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
253 public void rWrite(ByteBuffer buffer){
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
254 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
255 sc.write(buffer);
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
256 } catch (IOException e) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
257 e.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
258 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
259 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
260 public void dispose() {
cf13bdba762b Initial revision
pin
parents:
diff changeset
261 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
262 sc.close();
cf13bdba762b Initial revision
pin
parents:
diff changeset
263 } catch (IOException e) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
264 e.printStackTrace();
cf13bdba762b Initial revision
pin
parents:
diff changeset
265 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
266 }
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
267
31
ebbc14dd1a1a *** empty log message ***
pin
parents: 30
diff changeset
268 public void sendCmd(int cmd2, int line, int length, String lineText) {
25
32b28608baa6 *** empty log message ***
pin
parents: 24
diff changeset
269 //cmd = REP_INSERT_CMD;
29
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
270 //rWrite(pack(cmd2, sid, eid, seqid, line, lineText));
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
271 try {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
272 myCmdList.add(new Rep_Cmd(cmd2, sid, eid, seqid, line, length, lineText));
30
5723cfd85c95 *** empty log message ***
pin
parents: 29
diff changeset
273 //System.out.println("myCmdList : " + myCmdList.toString());
5723cfd85c95 *** empty log message ***
pin
parents: 29
diff changeset
274 //System.out.println("othersCmdList : " + othersCmdList.toString());
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
275 new Translate(myCmdList, othersCmdList);
29
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
276 for(Rep_Cmd userCmd:myCmdList){
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
277 rWrite(pack(userCmd.cmd, userCmd.sid, userCmd.eid, userCmd.seq, userCmd.lineno, userCmd.string));
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
278 myCmdList.remove(userCmd);
d2f8d056aae3 *** empty log message ***
pin
parents: 28
diff changeset
279 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
280 } catch (Exception e) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
281 e.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
282 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
283 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 20
diff changeset
284
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
285 }