Revision 420
Connection detection between the server and applet works. When disconnected, the user has the option to reconnect.
trunk/code/projects/colonet/ColonetGUI/Colonet.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
//Used for the robot controller |
31 | 31 |
final int VECTOR_CONTROLLER_HEIGHT = 220; |
32 |
final int VECTOR_CONTROLLER_WIDTH = 250;
|
|
32 |
final int VECTOR_CONTROLLER_WIDTH = 350;
|
|
33 | 33 |
|
34 | 34 |
|
35 | 35 |
// Connection |
... | ... | |
328 | 328 |
btnGetXBeeIDs.addActionListener(this); |
329 | 329 |
panelGraph.addMouseListener(this); |
330 | 330 |
this.addMouseMotionListener(this); |
331 |
|
|
332 | 331 |
|
333 |
// Set up dependent threads
|
|
332 |
// Set up animation threads
|
|
334 | 333 |
indicator = new SelectionIndicator(canvas); |
335 | 334 |
indicator.setRadius(RADIUS+3, 15); //a tad more than the bot radius |
336 |
webcamLoader = new WebcamLoader(this); |
|
337 |
dataUpdater = new DataUpdater(); |
|
338 |
csi = new ColonetServerInterface(this); |
|
339 | 335 |
|
340 | 336 |
} |
341 | 337 |
|
... | ... | |
547 | 543 |
|
548 | 544 |
} |
549 | 545 |
|
546 |
public void connect () { |
|
547 |
webcamLoader = new WebcamLoader(this); |
|
548 |
dataUpdater = new DataUpdater(); |
|
549 |
csi = new ColonetServerInterface(this); |
|
550 |
csi.connect(txtHost.getText(), txtPort.getText()); |
|
551 |
if (!csi.isReady()) |
|
552 |
return; |
|
553 |
btnConnect.setEnabled(false); |
|
554 |
lblConnectionStatus.setText("Status: Connected"); |
|
555 |
dataUpdater.start(); |
|
556 |
webcamLoader.start(); |
|
557 |
} |
|
558 |
|
|
559 |
public void disconnect () { |
|
560 |
btnConnect.setEnabled(true); |
|
561 |
lblConnectionStatus.setText("Status: Disconnected"); |
|
562 |
try { drawThread.interrupt(); } catch (Exception e) { } |
|
563 |
try { indicator.interrupt(); } catch (Exception e) { } |
|
564 |
|
|
565 |
} |
|
566 |
|
|
550 | 567 |
/** |
551 | 568 |
* Parses a String containing a task queue update. |
552 | 569 |
* Format is currently not specified. |
... | ... | |
688 | 705 |
|
689 | 706 |
//Connection |
690 | 707 |
if (source == btnConnect) { |
691 |
csi.connect(txtHost.getText(), txtPort.getText()); |
|
692 |
if (!csi.isReady()) |
|
693 |
return; |
|
694 |
btnConnect.setEnabled(false); |
|
695 |
dataUpdater.start(); |
|
696 |
drawThread = new Thread(this, "drawThread"); |
|
697 |
drawThread.start(); |
|
698 |
indicator.start(); |
|
699 |
webcamLoader.start(); |
|
708 |
connect(); |
|
700 | 709 |
} else if (source == btnGetXBeeIDs) { |
701 | 710 |
csi.sendXBeeIDRequest(); |
702 | 711 |
} |
... | ... | |
921 | 930 |
String line; |
922 | 931 |
while (true) { |
923 | 932 |
try { |
924 |
//if the socket is closed, make sure we can reconnect |
|
925 |
if (csi.getSocket().isInputShutdown()) |
|
926 |
btnConnect.setEnabled(true); |
|
927 | 933 |
//request more data |
928 | 934 |
if (csi != null && csi.isReady()) { |
929 | 935 |
//csi.sendSensorDataRequest(); |
trunk/code/projects/colonet/ColonetGUI/ColonetServerInterface.java | ||
---|---|---|
163 | 163 |
return false; |
164 | 164 |
} |
165 | 165 |
|
166 |
public String getLine () { |
|
167 |
if (this.isReady()) { |
|
168 |
try { |
|
169 |
return reader.readLine(); |
|
170 |
} catch (IOException e) { |
|
171 |
return null; |
|
172 |
} |
|
173 |
} else { |
|
174 |
return null; |
|
175 |
} |
|
166 |
public String getLine () throws IOException { |
|
167 |
return reader.readLine(); |
|
176 | 168 |
} |
177 | 169 |
|
178 | 170 |
/** |
... | ... | |
200 | 192 |
|
201 | 193 |
try { |
202 | 194 |
socket = new Socket(strHost, port); |
195 |
socket.setKeepAlive(true); |
|
203 | 196 |
} catch (UnknownHostException e) { |
204 | 197 |
log.append("Unknown host exception.\n"); |
205 | 198 |
err("Unknown Host Exception"); |
... | ... | |
228 | 221 |
|
229 | 222 |
} |
230 | 223 |
|
224 |
public void disconnect () { |
|
225 |
|
|
226 |
} |
|
227 |
|
|
231 | 228 |
/* |
232 | 229 |
* sendString - only this method should actually write data to the output stream |
233 | 230 |
*/ |
... | ... | |
460 | 457 |
String line; |
461 | 458 |
while (true) { |
462 | 459 |
try { |
463 |
line = getLine();
|
|
464 |
if (line != null) {
|
|
465 |
parseData(line);
|
|
466 |
}
|
|
460 |
line = reader.readLine();
|
|
461 |
if (line == null)
|
|
462 |
throw new IOException();
|
|
463 |
parseData(line);
|
|
467 | 464 |
Thread.sleep(DATALISTENER_DELAY); |
468 | 465 |
} catch (InterruptedException e) { |
469 | 466 |
return; |
470 |
} |
|
467 |
} catch (IOException e) { |
|
468 |
disconnect(); |
|
469 |
colonet.disconnect(); |
|
470 |
return; |
|
471 |
} |
|
471 | 472 |
} |
472 | 473 |
} |
473 | 474 |
|
... | ... | |
500 | 501 |
|
501 | 502 |
} |
502 | 503 |
|
503 |
} |
|
504 |
} |
trunk/code/projects/colonet/ColonetGUI/Makefile | ||
---|---|---|
20 | 20 |
|
21 | 21 |
default: $(DIR)/Colonet.class $(DIR)/ColonetServerInterface.class $(DIR)/Colonet.jar |
22 | 22 |
|
23 |
$(DIR)/Colonet.jar: |
|
23 |
$(DIR)/Colonet.jar: $(DIR)/Colonet.class $(DIR)/ColonetServerInterface.class
|
|
24 | 24 |
@echo --- Creating archive file --- |
25 |
cd $(DIR); jar cvf Colonet.jar *.class; jarsigner -keystore colonetkey -storepass colonet Colonet.jar colonet
|
|
25 |
cd $(DIR); jar cf Colonet.jar *.class; jarsigner -keystore colonetkey -storepass colonet Colonet.jar colonet |
|
26 | 26 |
@echo --- Done --- |
27 | 27 |
|
28 | 28 |
$(DIR)/Colonet.class: Colonet.java |
Also available in: Unified diff