static void Main(string[] args) { ThreadPool.QueueUserWorkItem(ClientTestData); ServerConfiguration config = new ServerConfiguration(); config.ServerType = ServerType.Master; config.Server = (Dns.Resolve(IPAddress.Any.ToString())).AddressList[0]; config.Port = 10086; config.BackLog = 1000; Server server = new Server(); server.Start(config); Console.WriteLine("Server Start Successfully"); Console.ReadLine(); }
public void Start(ServerConfiguration config) { Socket listenSocket = new Socket(AddressFamily.Unspecified, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(config.Server, config.Port); listenSocket.Bind(ep); listenSocket.Listen(config.BackLog); while (true) { // Set the event to nonsignaled state. allDone.Reset(); // Start an asynchronous socket to listen for connections and receive data from the client. Console.WriteLine("Waiting for a connection..."); StateObject state = new StateObject() { WorkSocket = listenSocket }; listenSocket.BeginAccept(Command.ByteLength, NewComingConnection, listenSocket); // Wait until a connection is made and processed before continuing. allDone.WaitOne(); } }