异步套接字接收确切数量的数据示例? [英] Async Socket Receive Exact amount of data Example?
本文介绍了异步套接字接收确切数量的数据示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我在确定如何接收确切数量的
Im having a bit of a problem working out how to receive an exact amount of
数据.我想接收确切数据的原因是,我有一个头,我从服务器接收到该头,该头具有数据的大小,然后从接收到的大小中,我可以算出我想要的确切数据量使用.
data. the reason i want to receive the exact amount of data is that i have a header that i recieve from a server this header has the size of the data then from the size received i can work out the exact amount of data i want to use.
所以问题是我如何指定要接收的数据量?
so the question is how can i specify the amount of data that i want to receive?
我尝试了以下示例,但是onrecieve回调将接收增量的数据. 数据.
I have tried the below example but the onrecieve callback would recieve incremented amounts of data.
// use OnRecieve callback
psSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(this.OnReceive), this.m_psSocket);
// callback
private void OnReceive(IAsyncResult ar)
{
Socket clientSocket = (Socket)ar.AsyncState;
int bytesRead = clientSocket.EndReceive(ar);
if (bytesRead > 0)
{
}
}
谢谢
推荐答案
也有一个类似于beginforceivemessagefrom的功能,用于TCP异步套接字
also is there a function similar to beginreceivemessagefrom for TCP async socket
这篇关于异步套接字接收确切数量的数据示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文