当前位置: 首页>>代码示例>>C#>>正文


C# IChannelHandlerContext.WriteAsync方法代码示例

本文整理汇总了C#中IChannelHandlerContext.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IChannelHandlerContext.WriteAsync方法的具体用法?C# IChannelHandlerContext.WriteAsync怎么用?C# IChannelHandlerContext.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IChannelHandlerContext的用法示例。


在下文中一共展示了IChannelHandlerContext.WriteAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteAsync

 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     if (message is int)
     {
         var buf = Unpooled.Buffer(4).WriteInt((int) message);
         return context.WriteAsync(buf);
     }
     return context.WriteAsync(message);
 }
开发者ID:helios-io,项目名称:helios,代码行数:9,代码来源:IntCodec.cs

示例2: WriteAsync

 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     if (message is int)
     {
         State = State.WriteMessages((int) message);
         Logger.Debug("[Client-Write] Writing: {0}", message);
     }
     return context.WriteAsync(message);
 }
开发者ID:helios-io,项目名称:helios,代码行数:9,代码来源:TcpClientSocketStateHandler.cs

示例3: ChannelRead

 public override void ChannelRead(IChannelHandlerContext context, object message)
 {
     var buffer = message as IByteBuffer;
     if (buffer != null)
     {
         Console.WriteLine("Received from client: " + buffer.ToString(Encoding.UTF8));
     }
     context.WriteAsync(message);
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:9,代码来源:EchoServerHandler.cs

示例4: WriteAsync

 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     var packet = message as PublishPacket;
     if (packet != null)
     {
         IByteBuffer result = ApplyCompression(packet.Payload, CompressionMode.Compress);
         packet.Payload = result;
     }
     return context.WriteAsync(message);
 }
开发者ID:kdotchkoff,项目名称:azure-iot-protocol-gateway,代码行数:10,代码来源:MqttPacketPayloadCompressionHandler.cs

示例5: ChannelRead

 public override void ChannelRead(IChannelHandlerContext context, object message)
 {
     var byteBuffer = message as IByteBuffer;
     if (byteBuffer != null)
     {
         this.buffer.Initialize();
         byteBuffer.Duplicate().ReadBytes(this.buffer, 0, byteBuffer.ReadableBytes);
         string msg = Encoding.UTF8.GetString(this.buffer);
         Console.WriteLine("Received from server: " + msg);
     }
     context.WriteAsync(message);
 }
开发者ID:l1183479157,项目名称:DotNetty,代码行数:12,代码来源:EchoClientHandler.cs

示例6: ContinueScenarioExecution

        void ContinueScenarioExecution(IChannelHandlerContext context)
        {
            if (!this.testScenario.MoveNext())
            {
                context.CloseAsync()
                    .ContinueWith(
                        t => this.completion.TrySetException(t.Exception),
                        TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
                this.completion.TryComplete();
                return;
            }
            foreach (object message in this.testScenario.Current.SendMessages)
            {
                context.WriteAsync(message)
                    .ContinueWith(
                        t => this.completion.TrySetException(t.Exception),
                        TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
            }

            context.Flush();
        }
开发者ID:l1183479157,项目名称:DotNetty,代码行数:21,代码来源:TestScenarioRunner.cs

示例7: WriteAsync

 public virtual Task WriteAsync(IChannelHandlerContext context, object message) => context.WriteAsync(message);
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:1,代码来源:ChannelHandlerAdapter.cs

示例8: ChannelRead

 public override void ChannelRead(IChannelHandlerContext context, object message)
 {
     context.WriteAsync(message);
 }
开发者ID:l1183479157,项目名称:DotNetty,代码行数:4,代码来源:EchoServerHandler.cs

示例9: ExecuteStep

        void ExecuteStep(IChannelHandlerContext context, TestScenarioStep currentStep)
        {
            if (!context.Channel.Open)
            {
                // todo: dispose scheduled work in case of channel closure instead?
                return;
            }

            Task lastTask = null;
            object lastMessage = null;
            foreach (object message in currentStep.Messages)
            {
                lastMessage = message;
                var writeTimeoutCts = new CancellationTokenSource();
                Task task = context.WriteAsync(message);
                object timeoutExcMessage = message;
                context.Channel.EventLoop.Schedule(
                    () => this.completion.TrySetException(new TimeoutException(string.Format("Sending of message did not complete in time: {0}", timeoutExcMessage))),
                    this.sendTimeout,
                    writeTimeoutCts.Token);
                task.ContinueWith(
                    t => writeTimeoutCts.Cancel(),
                    TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously);
                task.OnFault(t => this.completion.TrySetException(t.Exception));

                lastTask = task;
            }

            if (currentStep.WaitForFeedback)
            {
                if (this.responseTimeout > TimeSpan.Zero)
                {
                    this.responseTimeoutCts = new CancellationTokenSource();
                    if (lastTask == null)
                    {
                        this.ScheduleReadTimeoutCheck(context, null);
                    }
                    else
                    {
                        lastTask.ContinueWith(
                            t => this.ScheduleReadTimeoutCheck(context, lastMessage),
                            TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously);
                    }
                }
            }

            context.Flush();

            if (!currentStep.WaitForFeedback)
            {
                context.Channel.EventLoop.Execute(
                    ctx => this.ContinueScenarioExecution((IChannelHandlerContext)ctx),
                    context);
            }
        }
开发者ID:nberdy,项目名称:azure-iot-protocol-gateway,代码行数:55,代码来源:TestScenarioRunner.cs

示例10: ProcessPendingSubscriptionChanges

        async void ProcessPendingSubscriptionChanges(IChannelHandlerContext context)
        {
            try
            {
                do
                {
                    ISessionState newState = this.sessionState.Copy();
                    Queue<Packet> queue = this.SubscriptionChangeQueue;
                    var acks = new List<Packet>(queue.Count);
                    foreach (Packet packet in queue) // todo: if can queue be null here, don't force creation
                    {
                        switch (packet.PacketType)
                        {
                            case PacketType.SUBSCRIBE:
                                acks.Add(Util.AddSubscriptions(newState, (SubscribePacket)packet, this.maxSupportedQosToClient));
                                break;
                            case PacketType.UNSUBSCRIBE:
                                acks.Add(Util.RemoveSubscriptions(newState, (UnsubscribePacket)packet));
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }
                    queue.Clear();

                    if (!this.sessionState.IsTransient)
                    {
                        // save updated session state, make it current once successfully set
                        await this.sessionStateManager.SetAsync(this.deviceId, newState);
                    }

                    this.sessionState = newState;

                    // release ACKs

                    var tasks = new List<Task>(acks.Count);
                    foreach (Packet ack in acks)
                    {
                        tasks.Add(context.WriteAsync(ack));
                    }
                    context.Flush();
                    await Task.WhenAll(tasks);
                    PerformanceCounters.PacketsSentPerSecond.IncrementBy(acks.Count);
                }
                while (this.subscriptionChangeQueue.Count > 0);

                this.ResetState(StateFlags.ChangingSubscriptions);
            }
            catch (Exception ex)
            {
                ShutdownOnError(context, "-> UN/SUBSCRIBE", ex);
            }
        }
开发者ID:nberdy,项目名称:azure-iot-protocol-gateway,代码行数:53,代码来源:MqttIotHubAdapter.cs

示例11: WriteAsync

 public override Task WriteAsync(IChannelHandlerContext ctx, object msg)
 {
     if (this.Logger.IsEnabled(this.InternalLevel))
     {
         this.Logger.Log(this.InternalLevel, this.Format(ctx, "WRITE", msg));
     }
     return ctx.WriteAsync(msg);
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:8,代码来源:LoggingHandler.cs

示例12: WriteAsync

        public override Task WriteAsync(IChannelHandlerContext context, object message)
        {
            var buf = message as IByteBuffer;
            if (buf != null)
            {
                var tcs = new TaskCompletionSource<int>(buf);
                this.sslStreamWriteQueue.Enqueue(tcs);

                State oldState = this.state;
                if ((oldState & (State.WriteInProgress | State.Authenticated)) == State.Authenticated) // authenticated but not writing already
                {
                    this.state = oldState | State.WriteInProgress;
                    this.ScheduleWriteToSslStream(buf);
                }
                return tcs.Task;
            }
            else
            {
                // it's not IByteBuffer - passthrough
                // todo: non-leaking termination policy?
                return context.WriteAsync(message);
            }
        }
开发者ID:dalong123,项目名称:DotNetty,代码行数:23,代码来源:TlsHandler.cs

示例13: ChannelRead

            public override void ChannelRead(IChannelHandlerContext context, object message)
            {
                var buffer = (IByteBuffer)message;

                if (_logger.IsEnabled(LogLevel.Information))
                    _logger.Information($"接收到消息:{buffer.ToString(Encoding.UTF8)}。");

                var content = buffer.ToArray();
                TransportMessage<RemoteInvokeMessage> transportMessage;
                try
                {
                    transportMessage = _serializer.Deserialize<TransportMessage<RemoteInvokeMessage>>(content);
                }
                catch (Exception exception)
                {
                    _logger.Error($"将接收到的消息反序列化成 TransportMessage<RemoteInvokeMessage> 时发送了错误,消息内容:{{buffer.ToString(Encoding.UTF8)}}。", exception);
                    return;
                }

                var invokeMessage = transportMessage.Content;
                var entry = _serviceEntryLocate.Locate(invokeMessage);

                if (entry == null)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                        _logger.Error($"根据服务Id:{invokeMessage.ServiceId},找不到服务条目。");
                    return;
                }

                if (_logger.IsEnabled(LogLevel.Debug))
                    _logger.Debug("准备执行本地逻辑。");

                object result;

                try
                {
                    result = entry.Func(invokeMessage.Parameters);
                }
                catch (Exception exception)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                        _logger.Error("执行本地逻辑时候发生了错误。", exception);
                    result = null;
                }

                try
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                        _logger.Debug("准备发送响应消息。");
                    var resultData = _serializer.Serialize(new TransportMessage
                    {
                        Content = result,
                        Id = transportMessage.Id
                    });

                    buffer = Unpooled.Buffer(resultData.Length);
                    buffer.WriteBytes(resultData);
                    context.WriteAsync(buffer);
                    if (_logger.IsEnabled(LogLevel.Debug))
                        _logger.Debug("响应消息发送成功。");
                }
                catch (Exception exception)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                        _logger.Error("发送响应消息时候发生了异常。", exception);
                }
            }
开发者ID:yaozhenfa,项目名称:Rpc,代码行数:67,代码来源:DefaultServiceHost.cs

示例14: ChannelActive

 public override void ChannelActive(IChannelHandlerContext context)
 {
     // write a large enough blob of data that it has to be split into multiple writes
     var channel = context.Channel;
     _tasks.Enqueue(
         context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576))
             .ContinueWith(tr => channel.CloseAsync(),
                 TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion)
             .Unwrap());
     _tasks.Enqueue(context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576)));
     context.Flush();
     _tasks.Enqueue(context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576)));
     context.Flush();
 }
开发者ID:helios-io,项目名称:helios,代码行数:14,代码来源:TcpSocketChannelTest.cs

示例15: WriteAsync

 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     this.throughput.Increment();
     return context.WriteAsync(message);
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:5,代码来源:CounterHandlerOutbound.cs


注:本文中的IChannelHandlerContext.WriteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。