Java Blackberry 发送定制数据包
我需要在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决
这是我的做法,以便我的服务器端可以正确接收来自 BB 的数据包。
Resolved
Here is how i do it, so that my server side can recv the packets from BB correctly.