开发者

async CTP AcceptTcpClientAsync method

开发者 https://www.devze.com 2023-03-26 08:02 出处:网络
I\'m experimenting with the 开发者_运维知识库C# async CTP library and a socket server. I\'m trying to listen for connections using the extension method AcceptTcpClientAsync which is added onto the Sys

I'm experimenting with the 开发者_运维知识库C# async CTP library and a socket server. I'm trying to listen for connections using the extension method AcceptTcpClientAsync which is added onto the System.Net.Sockets.TcpListener class. My code looks like this:

  ...
        TcpListener listener = new TcpListener(IPAddress.Any, ServerPort);
        listener.Start();

        while (_active)
        {
            TcpClient client = await listener.AcceptTcpClientAsync();
            AddConnection(client);
        }

        listener.Stop();

  ...

However, if I put a breakpoint at AddConnection it is never hit. Am I using this correctly?


That looks fine to me - you should get to the break point only when something tries to actually connect. Sounds like a silly question but - is anything connecting? If so, what happens when it tries?

0

精彩评论

暂无评论...
验证码 换一张
取 消