当JAVA服务器(PC)通过蓝牙向错误的Android客户端发送消息时,该怎么办?
我正在开发一个应用程序,服务器(PC)通过蓝牙接受并处理Android客户端请求。我已经为连接的客户端创建了单独的线程。但是,当(例如)客户机A从服务器请求下一个数据时,服务器将数据发送给客户机B 以下是我的服务器代码片段:当JAVA服务器(PC)通过蓝牙向错误的Android客户端发送消息时,该怎么办?,java,android,multithreading,bluetooth,Java,Android,Multithreading,Bluetooth,我正在开发一个应用程序,服务器(PC)通过蓝牙接受并处理Android客户端请求。我已经为连接的客户端创建了单独的线程。但是,当(例如)客户机A从服务器请求下一个数据时,服务器将数据发送给客户机B 以下是我的服务器代码片段: public static void main(String[] args) throws IOException, SQLException, InstantiationException, IllegalAccessException { LocalDevic
public static void main(String[] args) throws IOException, SQLException, InstantiationException, IllegalAccessException {
LocalDevice localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());
UUID uuid = new UUID("1101", true);
String connectionString = "btspp://localhost:" + uuid +";name=Sample SPP Server";
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
System.out.println("\nServer Started. Waiting for clients to connect...");
while(true){
ClientClass c = new ClientClass(streamConnNotifier.acceptAndOpen(), id);
id++;
clientList.add(c);
Thread t = new Thread(c);
t.start();
}
}
ClientClass声明代码:
public class ClientClass implements Runnable {
private final StreamConnection _connection;
private final int _id;
public ClientClass(StreamConnection connection, int id){
this._connection = connection;
this._id = id;
}
public void run()
{
try {
RemoteDevice dev = RemoteDevice.getRemoteDevice(this._connection);
System.out.println("Remote device address: "+dev.getBluetoothAddress());
devName = dev.getFriendlyName(true);
inStream = this._connection.openInputStream();
outStream = this._connection.openOutputStream();
while(true){
BufferedReader bReader=new BufferedReader(new InputStreamReader(inStream));
String lineRead=bReader.readLine();
System.out.println(lineRead);
questionInit.checkAnswer(lineRead);
break;
}
}
提前非常感谢。ClientClass缺少run()方法。好的。我编辑了我的代码,但这不是run()方法中编写的唯一代码。并忽略其他方法,如questionInit的checkAnswer()