public class Main {
 public final UUID uuid = new UUID("27012f0c68af4fbf8dbe6bbaf7aa432a", false);
 public final String name = "Echo Server"; // the name of the service
 public final String url = "btspp://localhost:" + uuid.toString() // the service url
   + ";name=" + name + ";authenticate=false;encrypt=false;";
 LocalDevice local = null;
 StreamConnectionNotifier server = null;
 StreamConnection conn = null;
 public Main() {
  try {
   System.out.println("Setting device to be discoverable...");
   local = LocalDevice.getLocalDevice();
   local.setDiscoverable(DiscoveryAgent.GIAC);

   System.out.println("Start advertising service...");
   server = (StreamConnectionNotifier) Connector.open(url);
 
   System.out.println("Waiting for incoming connection...");
   conn = server.acceptAndOpen();

   System.out.println("Client Connected...");
   DataInputStream din = new DataInputStream(conn.openInputStream());
   while (true) {
    String a="";
    byte c;
    byte[] buffer = new byte[1024];
             int bytes;
             bytes = din.read(buffer);
             String readMessage = new String(buffer,0,bytes);
    System.out.println("msg : " + readMessage);
   }
  } catch (Exception e) {
   System.out.println("Exception Occured: " + e.toString());
  }
 }
 public static void main(String args[]) {
  Main echoserver = new Main();
 }
}


 

Bluecove 라이브러리를 이용한 블루투스 서버 예제 샘플인데요.

 

PC랑 연결은 잘 되는데 해제하는 방법을 모르겠습니다.. 서버에서 어떤식으로 해줘야 폰과 접속이 종료될까요?ㅠㅠ

 

server.close();  conn.close(); 이런걸 해봤는데 계속 접속상태를 유지하길래 궁금해서 올려봅니다 ㅠ