From bcccb386fe1dc20401b88ab0b0e493a8dbe7615c Mon Sep 17 00:00:00 2001 From: Sylvain Fonteneau Date: Tue, 23 Nov 2010 17:48:24 +0100 Subject: Enabled sending of large messages in MyTagClient. If the message is to large to fit in a single packet (its size is defined by MIU), then it need to be splited in multiple packets. Change-Id: I69eafac0b250b0f32901795b2ab80bad173ae35a --- src/com/android/nfc/mytag/MyTagClient.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/com/android/nfc/mytag/MyTagClient.java b/src/com/android/nfc/mytag/MyTagClient.java index d515f88..b42fb99 100755 --- a/src/com/android/nfc/mytag/MyTagClient.java +++ b/src/com/android/nfc/mytag/MyTagClient.java @@ -37,6 +37,7 @@ import java.io.IOException; */ public class MyTagClient extends BroadcastReceiver { private static final String TAG = "MyTagClient"; + private static final int MIU = 128; private static final boolean DBG = true; public MyTagClient(Context context) { @@ -69,17 +70,29 @@ public class MyTagClient extends BroadcastReceiver { public Void doInBackground(NdefMessage... msgs) { NfcService service = NfcService.getInstance(); NdefMessage msg = msgs[0]; + byte[] buffer = msg.toByteArray(); + byte[] tmpBuffer = new byte[MIU]; + int offset = 0; try { if (DBG) Log.d(TAG, "about to create socket"); // Connect to the my tag server on the remote side - LlcpSocket sock = service.createLlcpSocket(0, 128, 1, 1024); + LlcpSocket sock = service.createLlcpSocket(0, MIU, 1, 1024); if (DBG) Log.d(TAG, "about to connect"); // sock.connect(MyTagServer.SERVICE_NAME); sock.connect(0x20); - // Push the local NDEF message to the server - if (DBG) Log.d(TAG, "about to send"); - sock.send(msg.toByteArray()); + if (DBG) Log.d(TAG, "about to send a " + buffer.length + "-bytes message"); + while (offset < buffer.length) { + int length = buffer.length - offset; + if (length > tmpBuffer.length) { + length = tmpBuffer.length; + } + System.arraycopy(buffer, offset, tmpBuffer, 0, length); + if (DBG) Log.d(TAG, "about to send a " + length + "-bytes packet"); + sock.send(tmpBuffer); + offset += length; + } + if (DBG) Log.d(TAG, "about to close"); sock.close(); -- cgit v1.1