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

代码如下:
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;
        }

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问