Пример #1
0
  public static void main(String[] args) {
    if (args.length == 0) {
      gui = true;
      GUI.startGUI();
      btServer = new BTServer();
      try {
        btServer.startServer();
      } catch (IOException ioException) {
        Log.e(TAG, "IOexception!", ioException);
      }
    } else {
      try {
        out = new OutputStreamWriter(new FileOutputStream(args[0]));

        LocalDevice localDevice = LocalDevice.getLocalDevice();
        writeMessage("Local System:\n");
        writeMessage("Address: " + localDevice.getBluetoothAddress() + "\n");
        writeMessage("Name: " + localDevice.getFriendlyName() + "\n");

        btServer = new BTServer();
        btServer.startServer();
      } catch (IOException ioException) {
        Log.e(TAG, "IOException!", ioException);
      }
    }
  }
Пример #2
0
  public void run() {
    try {
      tryHandleClient();
    } catch (IOException ioException) {
      BTServer.logMessage(TAG, "BT Connection closed\n");
    }

    BTServer.writeMessage("Client disconnected!\n");
  }
Пример #3
0
  private void tryHandleClient() throws IOException {
    RemoteDevice dev = RemoteDevice.getRemoteDevice(this.connection);
    String client = dev.getFriendlyName(true);

    BTServer.writeMessage(
        "Address: " + dev.getBluetoothAddress().replaceAll("(.{2})(?!$)", "$1:") + "\n");
    BTServer.writeMessage("Remote device name: " + client + "\n");

    DataInputStream inStream = new DataInputStream(this.connection.openInputStream());
    OutputStream outStream = this.connection.openOutputStream();

    this.handle(inStream, outStream);

    outStream.close();
    inStream.close();
    this.connection.close();
  }