Example #1
0
 private void run_server()
 {
     try
     {
         listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         IPEndPoint BindingAddress = new IPEndPoint(IPAddress.Any, server_config.ListenPort);
         listen_socket.Bind(BindingAddress);
         listen_socket.Listen(1);
         is_server_running = true;
         while (!server_stop)
         {
             accepted_socket = listen_socket.Accept();
             Guarddog guard = new Guarddog(30000);
             guard.running = false;
             process_request();
             guard.Dispose();
             accepted_socket.Close();
         }
         Debug.Print("Server stopped");
     }
     catch (Exception)
     {
         is_server_running = false;
         OnServerErrorFunction(new ErrorEventArgs("Server Error\r\nCheck Connection Parameters"));
     }
 }
Example #2
0
 /// <summary>
 /// Use this to create a periodic time update thread
 /// </summary>
 /// <param name="period">The update period</param>
 public static void UpdateTime(int period = 43200000)
 {
     while (true)
     {
         //Set the server date/time via NTP
         Debug.Print("Setting server time");
         Guarddog guard = new Guarddog(10000);
         guard.running = false;
         SetDeviceNTP(timezone);
         guard.Dispose();
         Debug.Print("Server time set to: " + DateTime.Now.ToString());
         Thread.Sleep(period);
     }
 }