} // end TimerCallback static void Main(string[] args) { int counter = 0; int h1, m1, s1, i1 = 0; DateTime now = DateTime.Now; s1 = now.Second; m1 = now.Minute; h1 = now.Hour; i1 = (60 - s1) * 1000; // hybrid metering contains time-driven events every 5 minutes (TDM) Timer t = new Timer(TimerCallback, null, i1, 5000); //timer object every 5,000 milliseconds here // asynchronous event listener goes here (EDM) TcpListener serverSocket = new TcpListener(IPAddress.Parse("127.0.0.1"), 8888); TcpClient clientSocket = default(TcpClient); serverSocket.Start(); Console.WriteLine(">> " + "Multithread IAM server listens on 127.0.0.1:8888\r\n---------------------------------------------------"); counter = 0; while (true) { try { counter += 1; // new client added clientSocket = serverSocket.AcceptTcpClient(); // accept client socket connection Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started on " + clientSocket.Client.RemoteEndPoint); handleClient client = new handleClient(); client.startClient(clientSocket, Convert.ToString(counter)); } catch (Exception ex) { Console.WriteLine(">> " + ex.ToString()); clientSocket.Close(); serverSocket.Stop(); Console.WriteLine(">> " + "exit"); Console.ReadLine(); } } // add cleanup code here but make it reachable !!! } //end main
static void Main(string[] args) { int counter = 0; int h1, m1, s1, i1 = 0; DateTime now = DateTime.Now; s1 = now.Second; m1 = now.Minute; h1 = now.Hour; i1 = (60 - s1)*1000; // hybrid metering contains time-driven events every 5 minutes (TDM) Timer t = new Timer(TimerCallback, null, i1, 5000); //timer object every 5,000 milliseconds here // asynchronous event listener goes here (EDM) TcpListener serverSocket = new TcpListener(IPAddress.Parse("127.0.0.1"), 8888); TcpClient clientSocket = default(TcpClient); serverSocket.Start(); Console.WriteLine(">> " + "Multithread IAM server listens on 127.0.0.1:8888\r\n---------------------------------------------------"); counter = 0; while (true ) { try { counter += 1; // new client added clientSocket = serverSocket.AcceptTcpClient(); // accept client socket connection Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started on " + clientSocket.Client.RemoteEndPoint); handleClient client = new handleClient(); client.startClient(clientSocket, Convert.ToString(counter)); } catch (Exception ex) { Console.WriteLine(">> " + ex.ToString()); clientSocket.Close(); serverSocket.Stop(); Console.WriteLine(">> " + "exit"); Console.ReadLine(); } } // add cleanup code here but make it reachable !!! }