Java me 如何在j2me中使用蓝牙API创建多客户端服务器?
我计划使用J2ME实现一个使用蓝牙API的服务器。我希望多个客户端能够同时连接到它,但我在网上找不到太多Java me 如何在j2me中使用蓝牙API创建多客户端服务器?,java-me,bluetooth,Java Me,Bluetooth,我计划使用J2ME实现一个使用蓝牙API的服务器。我希望多个客户端能够同时连接到它,但我在网上找不到太多 UUID uuid = new UUID("1101", false); String SurveyAnswer=""; //Create the service url String connectionString = "btspp://localhost:" + uuid + ";name=xyz"; //open server url Str
UUID uuid = new UUID("1101", false);
String SurveyAnswer="";
//Create the service url
String connectionString = "btspp://localhost:" + uuid + ";name=xyz";
//open server url
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier) Connector.open(connectionString);
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
while(true){
StreamConnection connection = streamConnNotifier.acceptAndOpen();
}
如何修改这些代码以使其作为多客户端服务器工作?这是一个标准问题。当StreamConnection连接=streamConnNotifier.AcceptOnDopen()时;返回必须生成使用连接的线程。然后主线程重新输入accept并等待下一个连接
UUID uuid = new UUID("1101", false); String SurveyAnswer="";
//Create the service url
String connectionString = "btspp://localhost:" + uuid + ";name=xyz";
//open server url
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)
Connector.open(connectionString);
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
while(true){
StreamConnection connection = streamConnNotifier.acceptAndOpen();
System.out.println("Client connected starting communication");
new CommunicationThread(connection).start();
}
在类CommunicationThreads run方法中,您可以获取流并进行通信。目前的代码有什么问题?一次只能连接一个对等方。当一个对等方希望连接到服务,而另一个对等方的请求正在处理时,前者必须等待其请求被处理。您的通信读取是否扩展线程?start()属于线程