Ali
Ali

Reputation: 11570

Blue tooth Server and clients on black berry

Hi all I have created server and client using blackberry java programming ,but i am not able to create connection between client server , Server code is this

 public void run(){


//    m_strUrl= "btspp://localhost:" + RFCOMM_UUID + ";name=rfcommtest;authorize=true"; 
m_strUrl= "btspp://localhost;name=rfcommtest;authorize=true"; 

Dialog.alert(m_strUrl);

  // m_StrmConn = BTFACADE.waitForClient(SERVICE_NBR);

try
{
      localDevice = LocalDevice.getLocalDevice();
      localDevice.setDiscoverable(DiscoveryAgent.GIAC);
      //String connectionURL ="btspp://localhost:393a84ee7cd111d89527000bdb544cb1;authenticate=false;encrypt=false;name=RFCOMM Server";
      String connectionURL =m_ServerUrl;
      System.out.println("Server is started on"+m_ServerUrl);     
      streamConectionNotifier = (StreamConnectionNotifier)Connector.open(connectionURL);


      System.out.println("Server is statred on:"+m_strUrl);
      Dialog.alert("Server is statred on:"+m_strUrl);

      streamCon = streamConectionNotifier.acceptAndOpen(); 
      System.out.println("Connection is created");

      outputStream = streamCon.openOutputStream();
       inputStream = streamCon.openInputStream();
       String message="Hello this is server";
       byte data[]=message.getBytes();
       outputStream.write(data);
       System.out.println("Data is send to client");
}
catch (BluetoothStateException e)
{        
    Dialog.alert(e+"");

     System.err.println( "BluetoothStateException: " + e.getMessage() );    
} 
catch (IOException ex)
{
 Dialog.alert(ex+"");

       ex.printStackTrace();
}
catch(Exception e)
{
  System.err.println( "Exception: " + e.getMessage() );    
    Dialog.alert(e+"");

}

}

Upvotes: 0

Views: 142

Answers (1)

alxndr
alxndr

Reputation: 2407

The Sun Developer Network article "Using the Java APIs for Bluetooth, Part 2 - Putting the Core APIs to Work" describes creating and using Bluetooth server and client.

Upvotes: 1

Related Questions