问题描述
以下代码显示了如何将数据包从客户端发送到服务器的
套接字。文件大小(fileSizeTemp)在发送到服务器之前转换为网络字节顺序
。
*((unsigned short *)& dataBuff [6 + filenameLen + 1])= htons((无符号
短)(fileSizeTemp>> 16));
*((unsigned short *)& dataBuff [ 6 + filenameLen + 3])= htons((无符号
短)((fileSizeTemp<< 16)>> 16));
if(send(clientSock,...,...)== SOCKET_ERROR)
{
// ...
}
我的问题是,如何在服务器上获取文件的大小(来自收到的数据包)
?
谢谢
Manu。
ntohl。
Arnaud
MVP - VC
ntohl。
Arnaud
MVP - VC
命令
你可以用htonl更简单地做到这一点:
*((unsigned long *)& dataBuff [6 + filenameLen + 1])=
htonl(fileSizeTemp)
包)
ntohl。
Arnaud
MVP - VC
Hi,
Following code shows how a packet is sent from a client to a server''s
socket. The file size (fileSizeTemp) is converted to network byte order
before sending to the server.
*((unsigned short *)&dataBuff[6 + filenameLen + 1]) = htons((unsigned
short)(fileSizeTemp >> 16));
*((unsigned short *)&dataBuff[6 + filenameLen + 3]) = htons((unsigned
short)((fileSizeTemp << 16) >> 16));
if (send(clientSock, ..., ...) == SOCKET_ERROR)
{
//...
}
My question is, how to get the size of the file (from the received packet)
on the server?
Thanks
Manu.
ntohl.
Arnaud
MVP - VC
ntohl.
Arnaud
MVP - VC
order
You could do it more simply with htonl :
*((unsigned long *)&dataBuff[6 + filenameLen + 1]) =
htonl(fileSizeTemp)
packet)
ntohl.
Arnaud
MVP - VC
这篇关于从网络字节顺序获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!