Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android BluetoothServerSocket未从Accept方法返回_Android_Multithreading_Bluetooth_Block_Bluetooth Socket - Fatal编程技术网

Android BluetoothServerSocket未从Accept方法返回

Android BluetoothServerSocket未从Accept方法返回,android,multithreading,bluetooth,block,bluetooth-socket,Android,Multithreading,Bluetooth,Block,Bluetooth Socket,BluetoothServerSocketInstance.accept()不返回任何内容 下一步是不执行 在同一个位置上螺纹块 我见过许多类似的问题,但不幸的是,没有一个对我有帮助 我正在创建这样的接受线程 private class AcceptThread extends Thread { // The local server socket private String mSocketType; boolean isRunning = true; pri

BluetoothServerSocketInstance.accept()不返回任何内容 下一步是不执行

在同一个位置上螺纹块 我见过许多类似的问题,但不幸的是,没有一个对我有帮助

我正在创建这样的接受线程

private class AcceptThread extends Thread {
    // The local server socket

    private String mSocketType;
    boolean isRunning = true;
    private BluetoothServerSocket mmServerSocket;

    public AcceptThread(boolean isAndroid) {
        BluetoothServerSocket tmp = null;

        // Create a new listening server socket
        try {
            if (isAndroid)
                tmp = mAdapter.listenUsingRfcommWithServiceRecord(
                        NAME_SECURE, UUID_ANDROID_DEVICE);
            else
                tmp = mAdapter.listenUsingRfcommWithServiceRecord(
                        NAME_SECURE, UUID_OTHER_DEVICE);
        } catch (IOException e) {
        }
        mmServerSocket = tmp;
    }

    public void run() {
        setName("AcceptThread" + mSocketType);
        BluetoothSocket socket = null;

        // Listen to the server socket if we're not connected
        while (mState != BluetoothState.STATE_CONNECTED && isRunning) {

            try {
                // This is a blocking call and will only return on a
                // successful connection or an exception

                if (mmServerSocket != null)
                    socket = mmServerSocket.accept();

            } catch (IOException e) {
                break;
            }

            // If a connection was accepted
            if (socket != null) {
                synchronized (BluetoothService.this) {
                    switch (mState) {
                    case BluetoothState.STATE_LISTEN:
                    case BluetoothState.STATE_CONNECTING:
                        // Situation normal. Start the connected thread.
                        connected(socket, socket.getRemoteDevice(),
                                mSocketType);
                        break;
                    case BluetoothState.STATE_NONE:
                    case BluetoothState.STATE_CONNECTED:
                        // Either not ready or already connected. Terminate
                        // new socket.
                        try {
                            socket.close();
                        } catch (IOException e) {
                        }
                        break;
                    }
                }
            }
        }
    }

    public void cancel() {
        try {
            mmServerSocket.close();
            mmServerSocket = null;
        } catch (IOException e) {
        }
    }

    public void kill() {
        isRunning = false;
    }
}

这是预期的行为,它阻塞直到成功建立连接:这是预期的行为,它阻塞直到成功建立连接: