Android BluetoothSocket.connect() 返回,但相反的 Accept() 调用没有返回
我正在尝试让 Android 蓝牙 API 正常工作,但遇到了一个奇怪的问题。我有一个设备(Samsung Nexus S)作为客户端,调用socket.connect(),另一台设备(也是Samsung Nexus S)调用serverSocket.accept()(在进行设备发现之后,使用createInsecureRfcommSocketToServiceRecord和listenInsecure创建套接字。 ..)。
我将调试语句放在 connect() 之后,我可以看到 connect() 成功返回(因为如果没有成功返回,它会抛出异常)。然而,另一端的accept()调用只会阻塞,并最终超时。
有什么想法可能导致这种情况吗?据我所知,套接字正在连接,但我的进程没有被通知。
更新:
该错误的表现有点神秘,但我很确定我对线程处理不当,这在某种程度上阻止了运行accept()的线程解除阻塞。
I'm trying to get the Android Bluetooth APIs working, and I'm running into a strange problem. I have one device (Samsung Nexus S) as the client, calling socket.connect(), and the other device (also Samsung Nexus S) calling serverSocket.accept() (after doing device discovery, creating the sockets using createInsecureRfcommSocketToServiceRecord and listenInsecure...).
I put debug statements after connect(), and I can see that connect() is returning successfully (because it would throw an exception if it weren't). However, the accept() call on the other end just blocks, and eventually times out.
Any ideas what could cause this? As far as I can tell, the socket is connecting, but my process isn't being informed.
UPDATE:
The manifestation of the bug was a bit mysterious, but I'm pretty sure that I was mishandling threading, and that was somehow preventing the thread running accept() from unblocking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论