2011-04-27 81 views
0

大家好我已創建使用BlackBerry 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+""); 

} 

}

回答