非同期TCPサーバー私はただ1つのクライアントを取得できます。
複数のクライアントがある場合。サーバーで最初のクライアントを取得しますが、他のクライアントはクライアントで接続します。
これが私のサーバーコードです:
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);
}
}
}