public void Start() { // create a listening socket for clients to connect Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); // bind to the FT Server port listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort)); // set the socket to listen listeningSocket.Listen(clientBacklog); bool done = false; while (!done) { try { // accept a client connection Socket clientSocket = listeningSocket.Accept(); // instantiate connected client to process messages FTConnectedClient client = new FTConnectedClient(clientSocket); client.Start(); } catch (Exception ex) { Console.WriteLine("Error while accepting and starting client: " + ex.Message); Console.WriteLine("Waiting for 5 seconds and trying again..."); Thread.Sleep(5000); } } // close socket and quit listeningSocket.Close(); }
private static void ThreadProc(Object param) { // the procedure for the clientThread // when this method returns, the clientThread will exit // the param is a FTConnectedClient instance // start processing messages with the Run() method FTConnectedClient client = param as FTConnectedClient; client.Run(); }