Zack
Zack

Reputation: 871

TCP & UDP Over Wireless with Google Glass

I have developed both TCP and UDP applications for Google Glass. Here is the implementation for 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();
    }
}

I have a server constantly sending out packets every .5 seconds containing numbers. The Glass application receives the data and displays it on a TextView. I know that UDP is not reliable, but even with TCP I would get random "pauses" that would last for about 4 seconds followed by a lot of packet resends - By pausing of course, I mean that Glass is just dropping packets forcing the server to resend. Or even worse, with UDP just "drop and move on".

After doing further analysis, the application seems to pause ONLY when the following is shown in 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)

Once the IOException is thrown, everything goes back to normal and functions smoothly.

If I connect Glass to my phone via bluetooth, the message above does not display and everything runs perfectly (no pausing).

Why is the BluetoothSocket having such an impact on my application? Is there anything that I can do besides forcing the client to be connected via bluetooth before running the application?

Upvotes: 1

Views: 612

Answers (1)

JavaMaMocha
JavaMaMocha

Reputation: 70

Check out this thread on HERE

Btw, is your project open sourced?

Upvotes: 1

Related Questions