如何在新路面建造一个班子? 我有一个固定类别,称为服务器和一个称为客户Handler的非统计类别。 我愿在一条新路上主持一个新的客户Handler案的施工。 施工人有2个论点。 我尝试了多种办法,但我的工作已看得见,没有增加。 法典如下:
public static class Server
{
//...
public static void AcceptConnection(IAsyncResult iar)
{
var oldserver = (Socket) iar.AsyncState;
var client = oldserver.EndAccept(iar);
Console.WriteLine("Client [{0}] connected from {1}.", CHandlerIndex, client.RemoteEndPoint.ToString());
new ClientHandler(client, CHandlerIndex); //This has to run in a new thread.
CHandlerIndex++;
ServerSocket.BeginAccept(new AsyncCallback(AcceptConnection), ServerSocket);
}
}
public class ClientHandler
{
private readonly Socket _client;
private readonly Parser _pParser;
public Security S;
public int ClientIndex;
//...
public ClientHandler(Socket cSocket, int cI)
{
_client = cSocket;
InitSecurity();
_pParser = new Parser(this);
ClientIndex = cI;
}
//...
}