黑莓上的蓝牙服务器和客户端

时间:2011-04-27 10:53:13

标签: blackberry bluetooth

大家好我已经使用黑莓java编程创建了服务器和客户端,但是我无法在客户端服务器之间创建连接, 服务器代码是这个

 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+"");

}

}

1 个答案:

答案 0 :(得分:1)

Sun Developer Network文章“Using the Java APIs for Bluetooth, Part 2 - Putting the Core APIs to Work”介绍如何创建和使用蓝牙服务器和客户端。

相关问题