D
davis
Hi, I'm writing an app in bluetooth & wi-fi. It is client/server on
both. We have defined our own network protocol that should run over
both mediums. There are packet definitions of variable length.
Inside the packet, one field indicates its length. However, I don't
know ahead of time which packet shall be coming in when I read.
I'm using asynchronous read methods for both. In sockets, I do
Socket.BeginRead( ). This method must be supplied with a byte buffer,
and you must also specify the length to read as one of the parameters.
In the bluetooth, I do the same thing except with serial port profile
using Stream.BeginRead( ).
The problem thus becomes I must specify a byte buffer that is larger
than the packet to ensure I get it all. This causes annoying
post-processing where I must then parse the packet and truncate the
buffer to its real size.
I also don't like this b/c of possible buffer overflow.
My question is simply: is there a better way to do this?
both. We have defined our own network protocol that should run over
both mediums. There are packet definitions of variable length.
Inside the packet, one field indicates its length. However, I don't
know ahead of time which packet shall be coming in when I read.
I'm using asynchronous read methods for both. In sockets, I do
Socket.BeginRead( ). This method must be supplied with a byte buffer,
and you must also specify the length to read as one of the parameters.
In the bluetooth, I do the same thing except with serial port profile
using Stream.BeginRead( ).
The problem thus becomes I must specify a byte buffer that is larger
than the packet to ensure I get it all. This causes annoying
post-processing where I must then parse the packet and truncate the
buffer to its real size.
I also don't like this b/c of possible buffer overflow.
My question is simply: is there a better way to do this?