how do i get TcpListener to accept multiple connections and work with each one individually?

前端 未结 4 1381
野的像风
野的像风 2020-12-01 01:04

I have an SMTP listener that works well but is only able to receive one connection. My C# code is below and I am running it as a service. My goal is to have it runnign on a

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 01:35

    As per your code, you are starting one listener and receiving and processing message and closing program.

    You need to maintain a listener and TcpClient object can be passed to another function to process the message received. listener.Start();

            Console.WriteLine("Awaiting connection...");
            client = listener.AcceptTcpClient();
            Console.WriteLine("Connection accepted!");
    

提交回复
热议问题