protected async Task afterSending()
        {
            _listener.Start();

            using (var client = new TcpClient())
            {
                if (Dns.GetHostName() == destination.Host)
                {
                    await client.ConnectAsync(IPAddress.Loopback, destination.Port);
                }

                await client.ConnectAsync(destination.Host, destination.Port);

                await WireProtocol.Send(client.GetStream(), theMessageBatch, null, theSender);
            }
        }
Exemple #2
0
        public async Task SendBatch(ISenderCallback callback, OutgoingMessageBatch batch)
        {
            if (batch.Data.Length == 0)
            {
                throw new Exception("No data to be sent");
            }

            using (var client = new TcpClient())
            {
                var connection = connect(client, batch.Destination)
                                 .TimeoutAfter(5000);

                await connection;

                if (connection.IsCompleted)
                {
                    using (var stream = client.GetStream())
                    {
                        var protocolTimeout = WireProtocol.Send(stream, batch, batch.Data, callback);
                        //var protocolTimeout = .TimeoutAfter(5000);
                        await protocolTimeout.ConfigureAwait(false);

                        if (!protocolTimeout.IsCompleted)
                        {
                            await callback.TimedOut(batch);
                        }

                        if (protocolTimeout.IsFaulted)
                        {
                            await callback.ProcessingFailure(batch, protocolTimeout.Exception);
                        }
                    }
                }
                else
                {
                    await callback.TimedOut(batch);
                }
            }
        }