Google Glass 용으로 TCP 및 UDP 애플리케이션을 개발했습니다. 다음은 UDP 구현입니다.Google Glass로 TCP/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가 "drop and move on"하는 것만으로 더 나쁜 것입니다.
가 추가 분석을 수행 한 후, 응용 프로그램이 일시 중지 할 것 만 다음은 로그 캣에 표시 될 때 :
IOException가 슬로우되면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)
, 모든 것이 순조롭게 정상 기능으로 돌아 간다.
Glass를 블루투스를 통해 Glass에 연결하면 위의 메시지가 표시되지 않고 모든 것이 완벽하게 실행됩니다 (일시 중지 없음).
왜 BluetoothSocket이 내 응용 프로그램에 영향을 줍니까? 응용 프로그램을 실행하기 전에 클라이언트가 블루투스를 통해 강제로 연결될 수 있도록 할 수있는 다른 방법이 있습니까?
응답 해 주셔서 감사합니다. 이미 스레드를보고 응답을 게시했습니다. 내 프로젝트가 오픈 소스가 아닙니다. 내용은 내 바탕 화면에 로컬로 저장됩니다. 하지만이 작업은 간단한 소켓 응용 프로그램을 만들고 Glass를 통해 TCP 또는 UDP 트래픽을 생성하여 수행 할 수 있습니다. 나는 그 상태가 그 문제에 대해 "수락 됨"이라고 말했다. 그것이 그것이 문제라고 말했고 그것을 아직 고치지 않았다는 것을 의미하는지 확실하지 않았습니다. 이견있는 사람? Glass 지원 팀에 연락하여 커뮤니티 포럼에 나를 밀어 넣었습니다. – Zack
그 전형적인 반응 인 것 같습니다. 몇 달 전에 Glass에 대한 의도 지원을 추가하도록했으나 그 이후로 아무 것도 공개되지 않았습니다. Google이 제품 판매를 중단 한 이후로 더 이상 최우선 순위가 될 것이라고는 생각하지 않습니다. – JavaMaMocha
예, 앞으로 6 개월이 될 때까지 변경 사항이 표시 될 것으로 기대하지 않습니다. 하지만 고칠 수 없다면 나를 다시 유리로 보게 될거야 3.0 – Zack