00001 import java.io.IOException;
00002
00003 import javax.bluetooth.BluetoothStateException;
00004 import javax.bluetooth.DiscoveryAgent;
00005 import javax.bluetooth.LocalDevice;
00006 import javax.microedition.io.Connector;
00007 import javax.microedition.io.StreamConnectionNotifier;
00008
00009
00010
00011
00012
00013
00014
00015
00022 public class TicTacComServer extends TicTacCom {
00023
00024 private StreamConnectionNotifier notifier;
00025 private static String serverUrl = "btspp://localhost:" + RFCOMM_UUID + ";name=rfcommtest;authorize=true";
00026
00031 public TicTacComServer(TicTacMain p, int r) {
00032 super(p, r);
00033
00034 }
00035
00036 void initCom() throws IOException {
00037 conn = notifier.acceptAndOpen();
00038 }
00039
00041 void initAfterThread(){
00042 try{
00043
00044 initServer();
00045
00046
00047 }catch (BluetoothStateException e) {
00048 System.err.println( "Init "+role+": BluetoothStateException: " + e.getMessage() );
00049 } catch (IOException e) {
00050 System.err.println( "Init "+role+": IOException: " + e.getMessage() );
00051 }catch (Exception e) {
00052 System.err.println( "Init "+role+": Exception: " + e.getMessage() );
00053 }
00054
00055 }
00056
00058 void initServer() throws BluetoothStateException, IOException, Exception{
00059 conn = null;
00060 localDevice = LocalDevice.getLocalDevice();
00061 localDevice.setDiscoverable( DiscoveryAgent.GIAC );
00062
00063 notifier = (StreamConnectionNotifier)Connector.open(serverUrl);
00064
00065 initOK=true;
00066 }
00067
00068 }