On Fri, Dec 30, 2011 at 5:36 PM, SL <[email protected]> wrote:
>> ....
>>
>>   xxxaaaaThis is a greeting.
>>  where:
>>  xxx  - message type (3 bytes, text)
>> aaaa - integer, 4 bytes, length of text
>> 'This is a greeting.' - the actual text
>>
>> ....
>>
>>
>> There's no reason to use the NDK for this,
>>
>> The standard Java socket API can be used for this easily:
>>
>> http://docs.oracle.com/javase/tutorial/networking/sockets/
>>
>
> I am not sure, for example, how to retrieve the integer portion (ie 4
> bytes); any problem with Endian oddities ?
>
> Just thinking, can I use an object, serializable one ?
>
> Thanks.
>
>

I think you're making this way too complicated.  Endianness aside, why
are you even sending the message length unless you are conforming to
some protocol... You seem to be trying to reinvent the lower level
tcp/ip layers.  Why not just send your message and read the number of
bytes it is?  If you're using a buffered stream this shouldn't be an
issue, you might only need something like this if you had udp and you
were trying to put assurance on top of it..

And sure, you can use a serializable object, but like I said, there's
not really any need to.. If you go read that tutorial, especially the
last client /server example, I think you'll find that yours is a
common problem..

What are you using this for anyway?  If you go through some basic
examples in java sockets, this is a very basic problem you'd encounter
as a first project in any networks class, so it shouldn't be too hard
to learn given a few hours working through the tutorials.

kris

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to