是否有更好的方法通过套接字发送 float 据? 下面是发送数据的实现。
static float theOUTPUT[THE_FLOAT_DATA_BUFFER_SIZE];
int size = 2048;
int tb = 0;
int numbytes = 0;
int cs = 256;
unsigned char* buf = (unsigned char*)theOUTPUT;
while(tb < size) {
numbytes = send(sock, buf, cs, 0);
printf("bytes sent: %i\n", numbytes);
tb+=numbytes;
buf+=numbytes;
if(tb >= size) {
break;
}
}
最佳答案
在此代码中,不能保证 size
与 sizeof(theOUTPUT)
匹配。如果较少,那么您将丢失数据。
关于c - 浮点缓冲区转换为 unsigned char* 在套接字发送时丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4999178/