如何指定使用Socket.SendToAsync()时要发送的字节数?(How to specify the number of bytes to send when using Socket.SendToAsync()?)
我已经将基于UDP的协议实现从使用Socket.BeginXXX方法移植到Socket.XXXAsync方法,因为它们采用具有Buffer,Offset和Count属性的SocketAsyncEventArgs类,因此可以对单个大缓冲区进行分段并用于每个操作。
不幸的是我刚刚发现了设置:
mySocketAsyncEventArgs.SendPacketsSendSize
使用时发送数据报时不使用:
mySocket.SendToAsync(mySocketAsyncEventArgs);
而是发送SocketAsyncEventArgs.Buffer中的整个段来自Offset for Count字节! 我不能使用Socket.SendPacketsElements,因为那只适用于连接的套接字!
通常我只会发送几个字节,但有时会发送一千个..如果这些重载的重点是提高效率 - 它们没有帮助!
请告诉我有办法在每个操作中指定SocketAsyncEventArgs.Buffer中要发送的字节数。
I have ported my UDP based protocol implementation from using the Socket.BeginXXX methods to the Socket.XXXAsync methods as they take the SocketAsyncEventArgs class which has Buffer, Offset and Count properties so a single large buffer can be segmented and used for each operation.
Unfortunately I have just found out setting:
mySocketAsyncEventArgs.SendPacketsSendSize
Is not used when sending datagrams using:
mySocket.SendToAsync(mySocketAsyncEventArgs);
Instead the whole segment in SocketAsyncEventArgs.Buffer from Offset for Count bytes is sent! And I cannot use Socket.SendPacketsElements because that is only for connected Sockets!
Often I will only have a few bytes to send, but sometimes a thousand.. If the whole point of these overloads was to increase efficiency - they are not helping!
Please tell me there is way to specify the number of bytes to send in SocketAsyncEventArgs.Buffer on each operation..
原文:https://stackoverflow.com/questions/18042097