gpt4 book ai didi

android - TCP 和 UDP 无线与谷歌眼镜

转载 作者:行者123 更新时间:2023-11-30 02:27:11 25 4
gpt4 key购买 nike

我为 Google Glass 开发了 TCP 和 UDP 应用程序。这是 UDP 的实现:

public class MainActivity extends Activity
{
private TextView mTextView;
private someRunnable mRun;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
mTextView = (TextView) findViewById(R.id.textView);

Handler mHandler = new Handler()
{

@Override
public void handleMessage(Message msg)
{
Bundle bundle = msg.getData();
mTextView.setText(bundle.getString("message"));
super.handleMessage(msg);
}
};

try
{
mRun = new someRunnable(mHandler);
(new Thread(mRun)).start();
}
catch (IOException e)
{
Log.e("Error", "Unable to start Network activity");
Log.e("Error", e.getLocalizedMessage());
}
}

@Override
protected void onDestroy()
{
mRun.stopNetworkActivity();
super.onDestroy();
}
}

我有一个服务器每 .5 秒不断发送包含数字的数据包。 Glass 应用程序接收数据并将其显示在 TextView 上。我知道 UDP 不可靠,但即使使用 TCP,我也会得到随机的“暂停”,持续大约 4 秒,然后重新发送大量数据包——当然,暂停是指 Glass 只是丢弃数据包,迫使服务器重新发送。或者更糟的是,UDP 只是“放弃并继续前进”。

在做进一步分析后,当 LogCat 中显示以下内容时,应用程序似乎暂停:

01-05 16:22:43.812: W/BluetoothAdapter(951): getBluetoothService() called with no BluetoothManagerCallback
01-05 16:22:43.812: D/BluetoothSocket(951): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[122]}
01-05 16:22:48.203: W/bt-sdp(951): SDP - Rcvd conn cnf with error: 0x4 CID 0x40
01-05 16:22:48.203: E/btif_sock_rfcomm(951): find_rfc_slot_by_id unable to find RFCOMM slot id: 1356
01-05 16:22:53.336: W/bt-sdp(951): SDP - Rcvd conn cnf with error: 0x4 CID 0x42
01-05 16:22:53.336: E/btif_sock_rfcomm(951): find_rfc_slot_by_id unable to find RFCOMM slot id: 1357
01-05 16:22:53.336: W/BluetoothMapClientService(951): connection failed
01-05 16:22:53.336: W/BluetoothMapClientService(951): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
01-05 16:22:53.336: W/BluetoothMapClientService(951): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:521)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:532)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:323)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at com.android.bluetooth.map.BluetoothMapClientService.connect(BluetoothMapClientService.java:262)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at com.android.bluetooth.map.BluetoothMapClientService$1.connect(BluetoothMapClientService.java:94)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at android.bluetooth.IBluetoothMapClient$Stub.onTransact(IBluetoothMapClient.java:60)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at android.os.Binder.execTransact(Binder.java:404)
01-05 16:22:53.336: W/BluetoothMapClientService(951): at dalvik.system.NativeStart.run(Native Method)

一旦抛出 IOException,一切都会恢复正常并顺利运行。

如果我通过蓝牙将 Glass 连接到我的手机,上面的消息不会显示并且一切运行完美(没有暂停)。

为什么 BluetoothSocket 对我的应用程序有这样的影响?除了在运行应用程序之前强制客户端通过蓝牙连接之外,我还能做些什么吗?

最佳答案

HERE 上查看此线程

顺便问一下,您的项目是开源的吗?

关于android - TCP 和 UDP 无线与谷歌眼镜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27788686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com