开发者

When SendAsync is completed?

开发者 https://www.devze.com 2023-02-02 02:51 出处:网络
Hi Is there a way to make sure all message bytes had sent with SendAsync, there is no information provided in the callback of this method so how can assume all the messa开发者_高级运维ge had sent ??

Hi

Is there a way to make sure all message bytes had sent with SendAsync, there is no information provided in the callback of this method so how can assume all the messa开发者_高级运维ge had sent ?? And whats the maximum size of message we can send using socket in on Send operation ? is there any limitation exists or we can send data as large as we need ??

Thanks for clear responses ;)


Yes, all the information you need is in the callback:

    private void SendSAEA_Completed(object sender, SocketAsyncEventArgs sendSAEA)
    {        
            if (sendSAEA.BytesTransferred == 0 || sendSAEA.SocketError != SocketError.Success)
            {
                Close();
            }
            else
            {
                 // Process sendSAEA.BytesTransferred
            }
     }

Also, the buffer we can send in one Send operation, according to MSDN:

  • You can control the buffer size with: Socket.SendBufferSize.
  • The default is 8192.

(http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.sendbuffersize.aspx)

And, for SendAsync:

For message-oriented sockets, do not exceed the maximum message size of the underlying Windows sockets service provider. If the data is too long to pass atomically through the underlying service provider, no data is transmitted and the SendAsync method throws a SocketException with the SocketAsyncEventArgs.SocketError set to the native Winsock WSAEMSGSIZE error code (10040).

(http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.sendasync.aspx)


If the callback is called without an error indication then the message has been sent.

0

精彩评论

暂无评论...
验证码 换一张
取 消