本文整理汇总了Java中javax.bluetooth.RemoteDevice.getRemoteDevice方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteDevice.getRemoteDevice方法的具体用法?Java RemoteDevice.getRemoteDevice怎么用?Java RemoteDevice.getRemoteDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.bluetooth.RemoteDevice
的用法示例。
在下文中一共展示了RemoteDevice.getRemoteDevice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startserver
import javax.bluetooth.RemoteDevice; //导入方法依赖的package包/类
public void startserver() {
try {
String url = "btspp://localhost:" + uuid +
// new UUID( 0x1101 ).toString() +
";name=File Server";
StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);
StreamConnection con = service.acceptAndOpen();
OutputStream dos = con.openOutputStream();
InputStream dis = con.openInputStream();
InputStreamReader daf = new InputStreamReader(System.in);
BufferedReader sd = new BufferedReader(daf);
RemoteDevice dev = RemoteDevice.getRemoteDevice(con);
String greeting = "hi";
dos.write(greeting.getBytes(Charset.forName("utf-8")));
dos.flush();
byte buffer[] = new byte[1024];
int bytes_read = dis.read(buffer);
String received = new String(buffer, 0, bytes_read, Charset.forName("utf-8"));
System.out.println
("Message:" + received + "From:"
+ dev.getBluetoothAddress());
// con.close();
} catch (IOException e) {
System.err.print(e.toString());
}
}
示例2: startclient
import javax.bluetooth.RemoteDevice; //导入方法依赖的package包/类
public void startclient() {
try {
String remoteAddr = "001F8100011C";
String url = "btspp://" + remoteAddr + ":2";
StreamConnection con = (StreamConnection) Connector.open(url);
OutputStream os = con.openOutputStream();
InputStream is = con.openInputStream();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isr);
RemoteDevice dev = RemoteDevice.getRemoteDevice(con);
/** if (dev !=null) {
File f = new File("test.xml");
InputStream sis = new FileInputStream("test.xml");
OutputStream oo = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while ((len=sis.read(buf))>0)
oo.write(buf,0,len);
sis.close();
} **/
if (con != null) {
while (true) {
//sender string
System.out.println("Server Found:"
+ dev.getBluetoothAddress() + "\r\n" + "Put your string" + "\r\n");
String str = bufReader.readLine();
os.write(str.getBytes());
//reciever string
byte buffer[] = new byte[1024];
int bytes_read = is.read(buffer);
String received = new String(buffer, 0, bytes_read);
System.out.println("client: " + received + "from:" + dev.getBluetoothAddress());
}
}
} catch (Exception e) {
}
}
示例3: getNodeAddress
import javax.bluetooth.RemoteDevice; //导入方法依赖的package包/类
/**
*
* This method returns the node address.
*
* @param input String "localNode" to retreive the address of the local device.
* A ServiceRecord or StreamConnection object to retreive the address of a
* remote device.
*
* @return The node network address.
* @throws IOException
*/
public String getNodeAddress(Object input) throws IOException{
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
String inputString = (String)input;
// Make sure that we won't get any UPPER/lower case problems
inputString.toLowerCase();
if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
// Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
// This method is valid either the input type is ServiceRecord or StreamConnection.
RemoteDevice remoteDevice = null;
try{
ServiceRecord serviceRecord = (ServiceRecord) input;
remoteDevice = serviceRecord.getHostDevice();
}catch(ClassCastException cce1){
// Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
try{
StreamConnection streamConnection = (StreamConnection) input;
remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
}catch(ClassCastException cce2){
//This will only happen if the input object type is wrong
log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
}catch(IOException ioe){
log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
throw ioe;
}
}
return remoteDevice.getBluetoothAddress();
}