[英]Unable to receive the data (recv in cpp) put into socket(write() in java)
I'm new to socket programming so as to test some cases I'm using a java side client to send integer data through socket and I want ot receive that data on the server side in cpp. 我是套接字编程的新手,以便测试某些情况,我正在使用Java端客户端通过套接字发送整数数据,并且希望ot在cpp的服务器端接收该数据。
My code on client side (java) looks like 我在客户端(java)上的代码如下所示
out=new DataOutputStream(s.getOutputStream());
ar=1;
le=1;
out.writeInt(ar);
out.flush();
out.writeInt(le);
out.flush();
and im using recv function in cpp to receive this data. 和即时通讯使用cpp中的recv函数接收此数据。 the code on cpp side looks like
cpp端的代码看起来像
if (int(recv(acceptFD, &number, sizeof(int), 0)) != sizeof(int))
{
ALOGE ("error reading on socket: number of Args: %d,reutrned value =%d\n",number);
return;
}
for (int i = 0; i < number; i++)
{
int len;
if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int))
{
ALOGE ("error reading on socket: Len of Args: expected length :%d\n",len);
freeDebugCallbackArgs(i, args);
return;
}
and its showing the log as 并且将日志显示为
E/RILC ( 235): error reading on socket: number of Args: 16777216, returned value =-1073741824 E/RILC ( 235): error reading on socket: Len of Args: expected length :1075093557
E / RILC(235):套接字上读取错误:Args数:16777216,返回值= -1073741824 E / RILC(235):套接字上读取错误:Args透镜:预期长度:1075093557
It would be a great help if someone posts an answer to this. 如果有人发布答案,这将是一个很大的帮助。 Thank you
谢谢
I stongly suspect this is a problem with the byte order. 我tong然怀疑这是字节顺序的问题。
The number 16777206 represented as hex is 0x01000000, which is 1677206 in little-endian representation, but 1 in big-endian representation. 以十六进制表示的数字16777206为0x01000000,在小端表示中为1677206,在大端表示中为1。
Read your numbers as a byte array and include code to compensate for the different byte order between the Java source and C destination. 将您的数字读取为字节数组,并包括代码以补偿Java源代码和C目标代码之间不同的字节顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.