public static void StartAcceptLoop(int port) { IPAddress localAddr = IPAddress.Parse(ServerOptions.bindAddress); Server = new TcpListener(localAddr, port); //Switched to this one because TcpListener(port) is obsolete //Server = new TcpListener(port); try { Server.Start(); } catch (Exception) { MainClass.Exit("Can't listening address " + ServerOptions.bindAddress + " on port " + port, null); System.Environment.Exit(0); } Log.WriteLine("WinRSyncd starting, listening on port " + port); StopServer = false; ClientSockets = new List <TCPSocketListener>(); while (!StopServer) { try { Socket soc = Server.AcceptSocket(); if (!config.LoadParm(ServerOptions)) { continue; } TCPSocketListener socketListener = new TCPSocketListener(soc, ref ClientSockets); lock (ClientSockets) { ClientSockets.Add(socketListener); } socketListener.StartSocketListener(); for (int i = 0; i < ClientSockets.Count; i++) { if (ClientSockets[i] == null) { ClientSockets.RemoveAt(i); } } } catch (SocketException) { StopServer = true; } } if (ServerOptions.logFile != null) { ServerOptions.logFile.Close(); } }
public static void StartAcceptLoop(int port) { IPAddress localAddr = IPAddress.Parse(ServerOptions.bindAddress); Server = new TcpListener(localAddr, port); //Switched to this one because TcpListener(port) is obsolete //Server = new TcpListener(port); try { Server.Start(); } catch (Exception) { MainClass.Exit("Can't listening address " + ServerOptions.bindAddress + " on port " + port, null); System.Environment.Exit(0); } Log.WriteLine("WinRSyncd starting, listening on port " + port); StopServer = false; ClientSockets = new List<TCPSocketListener>(); while (!StopServer) { try { Socket soc = Server.AcceptSocket(); if (!config.LoadParm(ServerOptions)) { continue; } TCPSocketListener socketListener = new TCPSocketListener(soc, ref ClientSockets); lock (ClientSockets) { ClientSockets.Add(socketListener); } socketListener.StartSocketListener(); for (int i = 0; i < ClientSockets.Count; i++) { if (ClientSockets[i] == null) { ClientSockets.RemoveAt(i); } } } catch (SocketException) { StopServer = true; } } if (ServerOptions.logFile != null) { ServerOptions.logFile.Close(); } }