mPrintWriterClient = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mSocketClient.getOutputStream())),true);
...
public byte[] ITOA(int i)
{
ByteBuffer buff = ByteBuffer.allocate(4); buff.putInt(i);
buff.flip();
return buff.array();
}
public void SendData(int iM, int iA,int iR)
{
int iMsgSize=4*4;
byte a[] = ITOA(iM);
byte b[] = ITOA(iA);
byte c[] = ITOA(iR);
byte d[] = ITOA(iMsgSize);
byte buf[] = new byte[iMsgSize];
System.arraycopy(a,0,buf,0,4);
System.arraycopy(b,0,buf,4,4);
System.arraycopy(c,0,buf,8,4);
System.arraycopy(d,0,buf,12,4); Log.d(LOG_TAG,"Send Login msg "+buf[0]+","+buf[1]+","+buf[2]+","+buf[3]+","+buf[4]+","+buf[5]+","+buf[6]+","+buf[7]+","+buf[8]+","+buf[9]+","+buf[10]+","+buf[11]+","+buf[12]+","+buf[13]+","+buf[14]+","+buf[15]);
String msg = new String(buf);
try
{
mPrintWriterClient.print(msg.getBytes("utf_8"));//发送给服务器
// mPrintWriterClient.print(buf);//发送给服务器 mPrintWriterClient.flush();
Log.d(LOG_TAG,"Send Login msg "+msg+",len="+msg.length());
}
catch (Exception e)
{
Log.d(LOG_TAG, "发送异常:" + e.getMessage());
}
}
...
SendData(1,3,0);
Send Login msg 0,0,0,1,0,0,0,3,0,0,0,0,0,0,0,16
我发送的是:0,0,0,1,0,0,0,3,0,0,0,0,0,0,0,16
怎么到了pc服务端C语言socket收到的数据就变成:91,66,64,52,51,101,xx,xx,xx等乱七八糟的数据了?
导致PC端无法解析Android来的数据包!
怎么mPrintWriterClient.print都不行,请问这是大小端问题?字节序问题?编码问题?还是其他什么原因?!
如何解决这个问题,请各位大侠赐教,多谢!android socketsocket
...
public byte[] ITOA(int i)
{
ByteBuffer buff = ByteBuffer.allocate(4); buff.putInt(i);
buff.flip();
return buff.array();
}
public void SendData(int iM, int iA,int iR)
{
int iMsgSize=4*4;
byte a[] = ITOA(iM);
byte b[] = ITOA(iA);
byte c[] = ITOA(iR);
byte d[] = ITOA(iMsgSize);
byte buf[] = new byte[iMsgSize];
System.arraycopy(a,0,buf,0,4);
System.arraycopy(b,0,buf,4,4);
System.arraycopy(c,0,buf,8,4);
System.arraycopy(d,0,buf,12,4); Log.d(LOG_TAG,"Send Login msg "+buf[0]+","+buf[1]+","+buf[2]+","+buf[3]+","+buf[4]+","+buf[5]+","+buf[6]+","+buf[7]+","+buf[8]+","+buf[9]+","+buf[10]+","+buf[11]+","+buf[12]+","+buf[13]+","+buf[14]+","+buf[15]);
String msg = new String(buf);
try
{
mPrintWriterClient.print(msg.getBytes("utf_8"));//发送给服务器
// mPrintWriterClient.print(buf);//发送给服务器 mPrintWriterClient.flush();
Log.d(LOG_TAG,"Send Login msg "+msg+",len="+msg.length());
}
catch (Exception e)
{
Log.d(LOG_TAG, "发送异常:" + e.getMessage());
}
}
...
SendData(1,3,0);
Send Login msg 0,0,0,1,0,0,0,3,0,0,0,0,0,0,0,16
我发送的是:0,0,0,1,0,0,0,3,0,0,0,0,0,0,0,16
怎么到了pc服务端C语言socket收到的数据就变成:91,66,64,52,51,101,xx,xx,xx等乱七八糟的数据了?
导致PC端无法解析Android来的数据包!
怎么mPrintWriterClient.print都不行,请问这是大小端问题?字节序问题?编码问题?还是其他什么原因?!
如何解决这个问题,请各位大侠赐教,多谢!android socketsocket
解决方案 »
- 我的谷歌地图为什么无法显示啊啊啊啊!!!
- SurfaceView设置背景颜色遮挡问题
- 求助.如何从.aspx的页面中获取到字符串..
- 安卓教程共享有下载地址。!
- Android Gallery layout布局
- 关于Android程序性能的问题
- socket通讯的dataInputStream.readByte() 为负的问题
- 程序实现手机性能评测算法,如CPU运算,RAM IO,数据库IO等性能
- android studio 的module理解不了
- 英语不太好,新手入门,求教,求帮助该怎么搞定
- ArrayAdapter<String>的第三个参数问题
- 关于socket和serversocket的问题
具体你的这个原因我不太清楚,不过现在好像都用这个
struct
{
int a;
int b;
int c;
int d;
}
这样的数据包给服务端,我不知道我那样封装有没有问题?!
抓包提示malformed packet:RSL,真是多事之秋,有谁知道原因,请指教一下