在java和C的socket交互中 是用的是结构体传输 java怎么传 其实很简单 c中并没有Java的对象 他的结构体 你只要按照c中结构体的字段 转成字节数组就好了
比如
public byte[] MsgToBuf (MsgHead msgHead){
byte[] buf = new byte[20];
int msgh = msgHead.getMsgh();
int msgid = msgHead.getMsgid();
int cmd = msgHead.getCmd();
int error = msgHead.getError();
int dataL = msgHead.getDataL();
byte[] temp = clientUtils.intToByteArray(msgh);
// byte[] temp = clientUtils.tolh(msgh);
System.arraycopy(temp, 0, buf, 0, temp.length);
temp = clientUtils.intToByteArray(msgid);
// temp = clientUtils.tolh(msgid);
System.arraycopy(temp, 0, buf, 4, temp.length);
temp = clientUtils.intToByteArray(cmd);
// temp = clientUtils.tolh(cmd);
System.arraycopy(temp, 0, buf, 8, temp.length);
temp = clientUtils.intToByteArray(error);
// temp = clientUtils.tolh(error);
System.arraycopy(temp, 0, buf, 12, temp.length);
temp = clientUtils.intToByteArray(dataL);
// temp = clientUtils.tolh(dataL);
System.arraycopy(temp, 0, buf, 16, temp.length);
return buf;
}