Project

General

Profile

Revision 420

Added by Greg Tress about 16 years ago

Connection detection between the server and applet works. When disconnected, the user has the option to reconnect.

View differences:

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();

Also available in: Unified diff