No feedback from Socket.SendAsync

Posted by BowserKingKoopa on Stack Overflow See other posts from Stack Overflow or by BowserKingKoopa
Published on 2010-03-31T18:09:36Z Indexed on 2010/03/31 18:13 UTC
Read the original article Hit count: 399

Filed under:
|
|

I'm creating a socket and I'm trying to send data through it using SendAsync. My socket isn't connected to anything so I expected to get an error of some sort. However I get nothing. I get no indication that the send didn't work. If I use the synchronous Send method instead of the asynchronous SendAsync method I get an Exception stating that the socket isn't connected to anything. That makes sense to me. When using SendAsync the completed event doesn't ever fire and I get no indication that the send didn't work. So basically my question is how can I tell when SendAsync fails?

        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        SocketAsyncEventArgs args = new SocketAsyncEventArgs();
        args.SetBuffer(new byte[0], 0, 0);
        args.Completed += delegate(object sender, SocketAsyncEventArgs e)
        {
            Debug.WriteLine("async send complete");
            Debug.WriteLine("SOCKET ERROR: " + e.SocketError);
        };
        bool completedSynchronously = socket.SendAsync(args);
        if (completedSynchronously)
        {
            Debug.WriteLine("sync send complete");
            Debug.WriteLine("socket error: " + args.SocketError);
        }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#