C#:Socket.ReceiveAsync 和部分接收
当使用异步套接字时,特别是 Socket.ReceiveAsync,是否可以进行“部分”接收?例如,我想指定我期望 SocketAsyncEventArgs 对象有 1024 个字节,但我只想允许接收其中的一部分;例如,512 字节。因此,我不想等待所有 1024 字节可用,而是希望它回调这 512 字节。
这对于异步套接字来说是可能的吗?或者我需要诉诸非阻塞同步模式?
提前致谢。
When using asynchronous sockets, specifically, Socket.ReceiveAsync, is it possible to do a 'partial' receive? For example, I'd like to specify that I expect 1024 bytes on the SocketAsyncEventArgs object, but that I want to allow only receiving part of it; for instance, 512 bytes. So instead of waiting for all 1024 bytes to be available, I'd like it to call back with those 512 bytes.
Is this at all possible with asynchronous sockets? Or do I need to resort to non-blocking synchronous mode?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我在问题中描述的正是它的工作原理;如果指定 1024 字节,则接收到的字节可以是任何 <= 1024 字节。
Turns out, what I described in the question is exactly how it works; if one specifies 1024 bytes, the received bytes can be anything <= 1024 bytes.
只需指定您需要多少。剩下的下次还是这些,除非你说的是UDP……
Just specify how much you need. The rest will still be these next time, unless you're talking about UDP ...