annotate src/remoteeditor/network/REP.java @ 18:e87cae12907e

*** empty log message ***
author pin
date Tue, 31 Oct 2006 12:11:11 +0900
parents b409b85ab73f
children cc68a00f9850
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;
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
15
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
16
cf13bdba762b Initial revision
pin
parents:
diff changeset
17
cf13bdba762b Initial revision
pin
parents:
diff changeset
18 public class REP implements Runnable{
cf13bdba762b Initial revision
pin
parents:
diff changeset
19
cf13bdba762b Initial revision
pin
parents:
diff changeset
20 SocketChannel sc;
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
21 int cmd;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
22 int eid;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
23 int lineno;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
24 int sid;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
25 int seqid;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
26 int textsiz;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
27
15
535f124c2fc3 *** empty log message ***
pin
parents: 14
diff changeset
28 public static final int REP_INSERT_CMD = 6;
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
29 public static final int REP_INSERT_ACK_CMD = 7;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
30 public static final int REP_DELETE_CMD = 9;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
31 public static final int REP_DELETE_ACK_CMD = 10;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
32 public static final int REP_REPLACE_CMD = 13;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
33 public static final int REP_REPLACE_ACK_CMD = 14;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
34 public static final int REP_JOIN_CMD = 41;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
35 public static final int REP_JOIN_ACK_CMD = 42;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
36 public static final int REP_PUT_CMD = 45;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
37 public static final int REP_PUT_ACK_CMD = 46;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
38 public static final int REP_SELECT_CMD = 47;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
39 public static final int REP_SELECT_ACK_CMD = 48;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
40 public static final int REP_QUIT_CMD = 53;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
41 public static final int REP_QUIT_ACK_CMD = 54;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
42
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
43 //ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
44 //ByteBuffer read_buffer = ByteBuffer.allocateDirect(1024);
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
45
cf13bdba762b Initial revision
pin
parents:
diff changeset
46 String string;
cf13bdba762b Initial revision
pin
parents:
diff changeset
47 private RSocketListener socketListener;
cf13bdba762b Initial revision
pin
parents:
diff changeset
48 private Shell shell;
cf13bdba762b Initial revision
pin
parents:
diff changeset
49
14
0ac009f1c69e *** empty log message ***
pin
parents: 10
diff changeset
50 List myCmdList = new LinkedList();
16
b8f407692ecf *** empty log message ***
pin
parents: 15
diff changeset
51 List othersCmdList = new LinkedList();
14
0ac009f1c69e *** empty log message ***
pin
parents: 10
diff changeset
52
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
53 public REP() throws Exception {
cf13bdba762b Initial revision
pin
parents:
diff changeset
54 String host = "localhost";
1
c5c8358a14f3 add sample package
yabiku
parents: 0
diff changeset
55 int port = 8080;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
56
cf13bdba762b Initial revision
pin
parents:
diff changeset
57 InputDialog dialog = new InputDialog(shell, "REP", "host", "localhost", null);
cf13bdba762b Initial revision
pin
parents:
diff changeset
58 if(dialog.open() == Window.OK){
cf13bdba762b Initial revision
pin
parents:
diff changeset
59 host = dialog.getValue();
cf13bdba762b Initial revision
pin
parents:
diff changeset
60 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
61
1
c5c8358a14f3 add sample package
yabiku
parents: 0
diff changeset
62 dialog = new InputDialog(shell, "REP", "port", "8080", null);
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
63 if (dialog.open() == Window.OK) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
64 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
65 port = Integer.parseInt(dialog.getValue());
cf13bdba762b Initial revision
pin
parents:
diff changeset
66 } catch (NumberFormatException x) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
67 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
68 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
69
cf13bdba762b Initial revision
pin
parents:
diff changeset
70
cf13bdba762b Initial revision
pin
parents:
diff changeset
71 InetSocketAddress addr = new InetSocketAddress(host, port);
cf13bdba762b Initial revision
pin
parents:
diff changeset
72 sc = SocketChannel.open();
cf13bdba762b Initial revision
pin
parents:
diff changeset
73 sc.configureBlocking(true);
cf13bdba762b Initial revision
pin
parents:
diff changeset
74 sc.connect(addr);
cf13bdba762b Initial revision
pin
parents:
diff changeset
75 while(!sc.finishConnect()){
cf13bdba762b Initial revision
pin
parents:
diff changeset
76 System.out.println("afro");
cf13bdba762b Initial revision
pin
parents:
diff changeset
77 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
78 join();
cf13bdba762b Initial revision
pin
parents:
diff changeset
79
cf13bdba762b Initial revision
pin
parents:
diff changeset
80 dialog = new InputDialog(shell, "repput", "read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string, "hugo", null);
cf13bdba762b Initial revision
pin
parents:
diff changeset
81 if(dialog.open() == Window.OK){
cf13bdba762b Initial revision
pin
parents:
diff changeset
82 put();
cf13bdba762b Initial revision
pin
parents:
diff changeset
83 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
84
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
85 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
86 if(dialog.open() == Window.OK){
cf13bdba762b Initial revision
pin
parents:
diff changeset
87 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
88 sid = (byte) Integer.parseInt(dialog.getValue());
cf13bdba762b Initial revision
pin
parents:
diff changeset
89 } catch (NumberFormatException x) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
90 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
91 select();
cf13bdba762b Initial revision
pin
parents:
diff changeset
92 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
93 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
94
cf13bdba762b Initial revision
pin
parents:
diff changeset
95 public void join() throws IOException{
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
96 sc.write(pack( REP_JOIN_CMD, sid, eid, seqid, lineno, "afro"));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
97 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
98 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
99 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
100
cf13bdba762b Initial revision
pin
parents:
diff changeset
101 public void put() throws Exception {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
102 sc.write(pack(REP_PUT_CMD, sid, eid, seqid, lineno, "filename"));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
103 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
104 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
105 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
106
cf13bdba762b Initial revision
pin
parents:
diff changeset
107 public void select() throws Exception {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
108 sc.write(pack(REP_SELECT_CMD, sid, eid, seqid, lineno, "afro"));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
109 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
110 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
cf13bdba762b Initial revision
pin
parents:
diff changeset
111 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
112
cf13bdba762b Initial revision
pin
parents:
diff changeset
113 public void insert(int offset, int length, String text) throws IOException {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
114 cmd = REP_INSERT_CMD;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
115 seqid = (byte)offset;
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
116 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
117 try {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
118 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
119 System.out.println("myCmdList : " + myCmdList.toString());
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
120 } catch (Exception e) {
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
121 e.printStackTrace();
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
122 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
123 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
124
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
125 public void replace(int offset, int length, String text) throws IOException {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
126 cmd = REP_REPLACE_CMD;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
127 seqid = (byte)offset;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
128 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
129 try {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
130 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
131 System.out.println("myCmdList : " + myCmdList.toString());
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
132 } catch (Exception e) {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
133 e.printStackTrace();
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
134 }
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
135 }
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
136
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
137 public void delete(int offset, int length, String text) throws IOException {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
138 cmd = REP_DELETE_CMD;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
139 seqid = (byte)offset;
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
140 sc.write(pack(cmd, sid, eid, seqid, lineno, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
141 try {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
142 myCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, length, text));
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
143 System.out.println("myCmdList : " + myCmdList.toString());
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
144 } catch (Exception e) {
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
145 e.printStackTrace();
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
146 }
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
147 }
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
148
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
149 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
150
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
151 ByteBuffer buffer = ByteBuffer.allocateDirect(24+text.length()*2);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
152 buffer.clear(); // position = 0
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
153 buffer.putInt(cmd); buffer.putInt(sid); buffer.putInt(eid);
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
154 buffer.putInt(seqid); buffer.putInt(lineno);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
155 buffer.putInt(text.length()*2);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
156 //buffer.putString(text);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
157 System.out.println("pack:" + cmd +", "+ "length="+ text.length() +" "+ sid +", "+ eid +", "+ seqid +", "+ lineno);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
158
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
159 for(int i=0;i<text.length();i++) {
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
160 buffer.putChar(text.charAt(i));
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
161 }
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
162 buffer.flip(); // limit = current position, position = 0
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
163 return buffer;
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
164 }
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
165
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
166
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
167 static final int HEADER_SIZE = 24;
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
168 //ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
169
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
170 public void unpack() throws IOException{
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
171 ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
172 long len;
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
173 header.clear();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
174 len = sc.read(header); // limit = read length
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
175 if (len !=HEADER_SIZE) {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
176 System.out.println("‚Ä‚·");
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
177 // this can't happen
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
178 }
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
179 header.rewind(); // position = 0
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
180 /*for(int i = 0; i < 24; i++){
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
181 readbyte[i] = header.get();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
182 //System.out.println(readbyte[i]);
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
183 }*/
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
184 String text = "";
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
185 cmd = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
186 sid = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
187 eid = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
188 seqid = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
189 lineno = header.getInt();
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
190 textsiz = header.getInt()/2;
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
191
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
192 ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2);
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
193 //buffer.limit(textsiz*2);
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
194 //buffer.rewind();
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
195 len = sc.read(textBuffer); // limit = read length
9
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
196 if (len !=HEADER_SIZE) {
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
197 // this can't happen
ff7e7833cded pack/ unpack with putInt/getInt and ByteBuffer
pin
parents: 8
diff changeset
198 }
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
199 textBuffer.rewind();
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
200 for(int i=0;i<textsiz;i++) {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
201 text +=textBuffer.getChar();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
202 }
8
bf97ccde466d *** empty log message ***
fuchita
parents: 1
diff changeset
203 string = text;
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
204 try {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
205 othersCmdList.add(new Rep_Cmd(cmd, sid, eid, seqid, lineno, textsiz, text));
17
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
206 } catch (Exception e) {
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
207 e.printStackTrace();
b409b85ab73f *** empty log message ***
pin
parents: 16
diff changeset
208 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
209 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
210
cf13bdba762b Initial revision
pin
parents:
diff changeset
211 public void addSocketListener(RSocketListener socketListener){
cf13bdba762b Initial revision
pin
parents:
diff changeset
212 Thread th = new Thread(this);
cf13bdba762b Initial revision
pin
parents:
diff changeset
213 th.start();
cf13bdba762b Initial revision
pin
parents:
diff changeset
214 this.socketListener = socketListener;
cf13bdba762b Initial revision
pin
parents:
diff changeset
215 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
216
cf13bdba762b Initial revision
pin
parents:
diff changeset
217 public void run() {
cf13bdba762b Initial revision
pin
parents:
diff changeset
218 while(sc.isConnected()){
10
e40c010c703b *** empty log message ***
pin
parents: 9
diff changeset
219
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
220 try {
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
221 unpack();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
222 } catch (IOException e) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
223 e.printStackTrace();
cf13bdba762b Initial revision
pin
parents:
diff changeset
224 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
225 System.out.println("read packet:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ textsiz +", "+ string);
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
226 //socketListener.packetReceived(new RSocketEvent(cmd, sid, eid, seqid, lineno, textsiz, string)); //
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
227 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
228
cf13bdba762b Initial revision
pin
parents:
diff changeset
229 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
230
cf13bdba762b Initial revision
pin
parents:
diff changeset
231 public void dispose() {
cf13bdba762b Initial revision
pin
parents:
diff changeset
232 try {
cf13bdba762b Initial revision
pin
parents:
diff changeset
233 sc.close();
cf13bdba762b Initial revision
pin
parents:
diff changeset
234 } catch (IOException e) {
cf13bdba762b Initial revision
pin
parents:
diff changeset
235 e.printStackTrace();
cf13bdba762b Initial revision
pin
parents:
diff changeset
236 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
237 }
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
238
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
239 }