Java Blackberry 发送定制数据包

发布于 2024-12-07 10:43:58 字数 1356 浏览 1 评论 0原文

我需要在 Java 中为 Blackberry 设备重新创建此数据包:

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);

我已经知道我应该使用它

OutputStreamWriter 

,但我不知道如何在 Java 中重新创建该数据包,您能帮忙吗?

更新 好吧,我认为我说得对:

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);    

似乎工作正常,有点“oldsKewl”的做法 - 所以如果你们有更好的选择,我将不胜感激。

只是为了确认一下,这样做是有效的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2024-12-14 10:43:58

已解决

这是我的做法,以便我的服务器端可以正确接收来自 BB 的数据包。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文