--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/summerofcode/mel/RoutingSMS/client/Client.java Sun Aug 28 20:59:53 2005 -0400
@@ -0,0 +1,227 @@
+import javax.bluetooth.*; +import javax.microedition.io.*; //for StreamConnection class +import java.lang.Object; + //application variables + public static String number = ""; //to get the number entered by the user + public static boolean importedPhonebook; //set to true after the client imports the phone book + public static boolean importingPhonebook; //set to true if the operation of importing the phonebook was successful otherwise set to false + public static Vector contactNumbers; //holds the contacts number in phonebook + public static Vector contactNames; //holds the contacts names in phonebook + public static Vector unsuccessfulNumbers; // holds the numbers that were not successfuly sent + public static boolean serverSendingResponse; //set to true when the server sends a message indicating the success of sending the sms + private StreamConnection streamConnection = null; + /*private*/ DataOutputStream out = null; + /*private*/ DataInputStream in = null; + private String connectionURL; + boolean connectionOpen; + * Constructor initializes attributes. + contactNumbers = new Vector(); + contactNames = new Vector(); + unsuccessfulNumbers = new Vector (); //unsuccessfully sent numbers + importedPhonebook = false; + *now it is capable of receiving address book, + *when it is set to false it indicates that an error occured + *while retrieving the phone book and so the client doesnt keep waiting for the server. + importingPhonebook = true; + serverSendingResponse = false; + connectionOpen = false; + public void run_client (ServiceRecord r) + String url = r.getConnectionURL(ServiceRecord.AUTHENTICATE_NOENCRYPT, false ); + if (connectionOpen == true) + //reading phonebook from the phone + importedPhonebook = false; //still doesnt have the phone book + importingPhonebook = false; //unable to import the phonebook + * Connects to the server and retrieves the address book + public void retrieveContacts () + number_name = in.readUTF(); + while(!number_name.equals("EOF") ) //EOF indicates that the end of list was reached + if (number_name.equals ("EXCEPTION")) + {//this exception is raised from the phone side (for exmaple if the user refused to give permission to the application to access PIM library) + importedPhonebook = false; + importingPhonebook = false; + number = number_name.substring(0,number_name.indexOf(" ")); + name = number_name.substring(number_name.indexOf(" ")+1,number_name.length()); + contactNumbers.addElement(number); + contactNames.addElement(name); + Jout("read in data "+number_name+""); + number_name = in.readUTF(); + importedPhonebook = true; //succeeded importing the phone book + * connects to the server and sends the sms entered by the user + * to the cell phone via bluetooth + public void SMSroute (String message, int countRecipients, String[] desiredNumbers) + unsuccessfulNumbers.removeAllElements(); //clears the vector bec of batch sending + serverSendingResponse = false; + out.writeUTF (message); + out.write (countRecipients); //the number of the recipients entered by the user + for (int i=0; i<countRecipients; i++) + out.writeUTF (desiredNumbers[i]); //desired numbers entered by the user + success (); //waits for server reply indicating its success or failure of sending the sms + * This method receives from the server a message indicates whether ir was successful + * in sending the sms to the desired phone numbers + * if it failed to send the sms to any of the desired numbers, + * it notifies the client with those numbers to report to the user. + String theUnsuccessful = null; + serverSendingResponse = true; + for (int i = 0 ; i < intSize; i++) + theUnsuccessful = in.readUTF (); + unsuccessfulNumbers.addElement(theUnsuccessful); //vector of unsuccessful numbers + serverSendingResponse = true; + * Initializes connection and streams between PC and Cellular phone. + public boolean openConnection() + streamConnection = (StreamConnection) Connector.open(connectionURL); + out = streamConnection.openDataOutputStream(); + in = streamConnection.openDataInputStream(); + connectionOpen = false; + * Called when user disconnects connection or exception + * occurs during connection. Connection and streams between devices are closed. + public void closeConnection() + streamConnection.close(); + connectionOpen = false; + catch (IOException ioe) + public void Jout (String s)