Async Tcp Server I just can get one client.
When I have more than one client.I just get first client in server,but others client connected in client.
Here is my server code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
namespace BeginAcceptTcpClientserver
{
class Program
{
static void Main(string[] args)
{
TcpListener listener = new TcpListener(1234);
listener.Start();
listener.BeginAcceptTcpClient(callbake,listenner);
Console.WriteLine("print q to quit");
ConsoleKey key;
do
{
key = Console.ReadKey().Key;
} while (key != ConsoleKey.Q);
}
static void callbake(IAsyncResult ar)
{
TcpClient clienter = ((TcpListener)ar.AsyncState).EndAcceptTcpClient(ar);
Console.WriteLine("---client connect {0}<--{1} ---", clienter.Client.LocalEndPoint, clienter.Client.RemoteEndPoint);
}
}
}
TcpListener.BeginAcceptTcpClient only listens for one incoming connection. You need to call it again and again, perhaps in your callback method: