L
logiclips
Hi,
I'm sending data between a cell-phone and a PC via Bluetooth:
This works for strings and numbers when I explicitly set them (e.g. int
sendData = 3), but when I want to send data which is computed in the
follwing way, it doesn't work properly:
/* CLIENT */
// rawData.length is between 100.000- 2.000.000
int packetSize = 256;
int numPackets = (int)(rawData.length / packetSize);
byte[] packet = new byte[packetSize];
// write number of packets
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(packetSize);
byte[] rawNumPackets = baos.toByteArray(); //write 4 byte
//send number of packets
connection.send(rawNumPackets);
/* SERVER */
byte[] rawNumPackets = new byte[4];
int length = connection.receive(rawNumPackets);
ByteArrayInputStream bais = new ByteArrayInputStream(rawNumPackets);
DataInputStream dis = new DataInputStream(bais);
int numPackets = dis.readInt();
So, the problem is the following:
When I compute on client side the value numPackets and print it out I
get an value of 542. This int value I send to my server, but here I
receive 434.
When I put on client side int numPackets = 542, then I receive on
server side 542.
This happens with every number.
That makes completely no sense to me!
Does anyone know what the reason for this could be?
Thanks,
Peter
I'm sending data between a cell-phone and a PC via Bluetooth:
This works for strings and numbers when I explicitly set them (e.g. int
sendData = 3), but when I want to send data which is computed in the
follwing way, it doesn't work properly:
/* CLIENT */
// rawData.length is between 100.000- 2.000.000
int packetSize = 256;
int numPackets = (int)(rawData.length / packetSize);
byte[] packet = new byte[packetSize];
// write number of packets
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(packetSize);
byte[] rawNumPackets = baos.toByteArray(); //write 4 byte
//send number of packets
connection.send(rawNumPackets);
/* SERVER */
byte[] rawNumPackets = new byte[4];
int length = connection.receive(rawNumPackets);
ByteArrayInputStream bais = new ByteArrayInputStream(rawNumPackets);
DataInputStream dis = new DataInputStream(bais);
int numPackets = dis.readInt();
So, the problem is the following:
When I compute on client side the value numPackets and print it out I
get an value of 542. This int value I send to my server, but here I
receive 434.
When I put on client side int numPackets = 542, then I receive on
server side 542.
This happens with every number.
That makes completely no sense to me!
Does anyone know what the reason for this could be?
Thanks,
Peter