RiverRat  - An MIT iCampus project http://web.mit.edu/riverrat/

Main Page | Software Documentation | Hardware Documentation | People | Contact | Wiki

Main Page | Class Hierarchy | Class List | File List | Class Members

RadioListener.java

00001 package riverrat;
00002 
00003 import java.io.*;
00004 import java.net.*;
00005 import java.util.*;
00006 
00012 public class RadioListener implements Runnable {
00014         static int port = 9999;
00015         
00017         static String host = "localhost";
00018         
00020         Race therace = null;
00021         
00025         public RadioListener() {
00026         }
00027         
00034         public RadioListener(Race race) {
00035                 therace = race;
00036         }
00037         
00047         public RadioListener(Race race, String connect_host, int connect_port) {
00048                 therace = race;
00049                 host = connect_host;
00050                 port = connect_port;
00051         }
00052         
00058         public void run() {
00059                 try {
00060                         System.out.println("connecting to radio on "+host+":"+port+"...");
00061                         InputStream input = (new Socket(host, port)).getInputStream();
00062                         System.out.println("connected to stream.");
00063                 } catch(UnknownHostException e) {
00064                         System.err.println("Host not found.");
00065                         System.exit(1);
00066                 } catch(SocketException e) {
00067                         System.err.println("Socket exception connecting to Radio host.");
00068                         System.exit(1);
00069                 } catch(IOException e) {
00070                         System.err.println("IO Exception connecting to Radio host.");
00071                         System.exit(1);
00072                 }
00073                 
00074                 //parse stream from radio here
00075                 
00076         }
00077         
00082         public static void main(String args[]) {
00083                 RadioListener rlistener = new RadioListener();
00084                 Thread listenthread = new Thread(rlistener);
00085                 listenthread.start();
00086                 while(true) {
00087                         System.out.println("This is the main loop.");
00088                         try {
00089                                 Thread.sleep(10000);
00090                         } catch(InterruptedException e) {
00091                                 System.err.println("Interrupted!");
00092                         }
00093                 }
00094         }
00095 }
 

Brought to you by the RiverRat team.