i need to recreate this within Java for Blackberry device:
char cPacketData[1024];
int thisPacketLength=( X_PACKET_SPACE*12 ) + ( 20*X_PACKET_SPACE );
(*(int *) (cPacketData)) =X_PACKET_START;
(*(int *) (cPacketData+X_PACKET_SPACE)) =thisPacketLength;
(*(int *) (cPacketData+X_PACKET_SPACE*2)) =X_PACKET_POSITION_DATA;
(*(int *) (cPacketData+X_PACKET_SPACE*3)) =positionX;
(*(int *) (cPacketData+X_PACKET_SPACE*4)) =positionY;
send(mSocket,(const char *)&cPacketData,thisPacketLength,0);
I already know that i should use
OutputStreamWriter
but i don't know how to recreate that packet in Java, can you please help?
UPDATE Ok, think i've got it right:
char[] payload = new char[100];
int start=9999;
payload[3] = (char)((start >> 24) & 0XFF);
payload[2] = (char)((start >> 16) & 0XFF);
payload[1] = (char)((start >> 8) & 0XFF);
payload[0] = (char)((start >> 0) & 0XFF);
int len=100;
payload[X_PACKET_SPACE+3] = (char)((len >> 24) & 0XFF);
payload[X_PACKET_SPACE+2] = (char)((len >> 16) & 0XFF);
payload[X_PACKET_SPACE+1] = (char)((len >> 8) & 0XFF);
payload[X_PACKET_SPACE] = (char)((len >> 0) & 0XFF);
_out.write(payload);
Seems to work fine, kinda 'oldsKewl' way of doing - so i would appreciate if you guys have any better option.
Just to confirm, it works by doing it this way.
Resolved
Here is how i do it, so that my server side can recv the packets from BB correctly.
OutputStream _out = conn.openOutputStream();
packet[3]= (byte)(9999 >>> 24);
packet[2]= (byte)(9999 >>> 16);
packet[1]= (byte)(9999 >>> 8);
packet[0]= (byte)(9999 >>> 0);
packet[8]= (byte)(60 >>> 24);
packet[7]= (byte)(60 >>> 16);
packet[6]= (byte)(60 >>> 8);
packet[5]= (byte)(60 >>> 0);
packet[13]= (byte)(4 >>> 24);
packet[12]= (byte)(4 >>> 16);
packet[11]= (byte)(4 >>> 8);
packet[10]= (byte)(4 >>> 0);
packet[18]= (byte)(_PIN >>> 24);
packet[17]= (byte)(_PIN >>> 16);
packet[16]= (byte)(_PIN >>> 8);
packet[15]= (byte)(_PIN >>> 0);
packet[23]= (byte)(1 >>> 24);
packet[22]= (byte)(1 >>> 16);
packet[21]= (byte)(1 >>> 8);
packet[20]= (byte)(1 >>> 0);
_out.write(packet,0,60);