谈谈如何使用Netty开发实现高性能的RPC服务器

展开阅读全文

有用过DOTNETTY的朋友嘛,链接错误WaitingForActivation

02-11

代码如下: public async void SimpleSend(bool bindClient, IByteBufferAllocator allocator, AddressFamily addressFamily, byte[] expectedData, int count) { var clientGroup = new MultithreadEventLoopGroup(1); var clientBootstrap = new Bootstrap(); clientBootstrap .Group(clientGroup) .ChannelFactory(() => new SocketDatagramChannel(addressFamily)) .Option(ChannelOption.Allocator, allocator) .Option(ChannelOption.SoBroadcast, true) .Option(ChannelOption.IpMulticastLoopDisabled, false) .Handler(new ActionChannelInitializer<IChannel>(channel => { channel.Pipeline.AddLast("Test", new NetUtil.TestHandler()); })); var clientEndPoint = new IPEndPoint( addressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, IPEndPoint.MinPort); IPAddress add = IPAddress.Parse(this.txtIP.Text); clientBootstrap .LocalAddress(clientEndPoint) .RemoteAddress(new IPEndPoint(add.Address, Int16.Parse(this.txtPort.Text))); Task <IChannel> task = null; if (bindClient) { IPAddress addressLocal = NetUtil.GetLoopbackAddress(addressFamily); task = clientBootstrap.BindAsync(clientEndPoint); //(clientEndPoint); Console.WriteLine(task); Int64 i = 1; while (!task.IsCompleted) { Console.WriteLine(task.Status); //《《==此处“WaitingForActivation” Thread.Sleep(10); } clientChannel = task.Result; Console.WriteLine(task.AsyncState); } else { task = (Task<IChannel>)clientBootstrap.RegisterAsync(); clientChannel = task.Result; } 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览