// Main loop to receive from a connection public static void RecieveFrom(Connection connection) { while (true) { try { // Attempt to add new Transmission to queue TransmissionsRecieved.Enqueue(new Tuple <Transmission, Connection>(Recieve(connection), connection)); // Signal Transmission has been received transmissionsRecievedSignal.Set(); } catch (System.IO.IOException) { // Remove connection when error occurs Console.WriteLine($"{connection.ConnectionID} (Connection): Disconnected (IOException)"); ServerConnections.Remove(connection); return; } catch (System.Security.Cryptography.CryptographicException) { // Remove connection when error occurs Console.WriteLine($"{connection.ConnectionID} (Connection): Disconnected (CryptographicException)"); ServerConnections.Remove(connection); return; } } }
public static void StartServer() { //UICONTROLLER.Display += (x) => { System.Console.WriteLine($"<{x.Author.Name}>: {x._message}"); }; //System.Console.WriteLine(Dns.GetHostName()); Task processTransmisisons = new Task(() => { ServerTransmissionHandler.OnTransmissionRecieved(); }); processTransmisisons.Start(); Task lookingForConenctions = new Task(LookForConnections); lookingForConenctions.Start(); lookingForConenctions.Wait(); processTransmisisons.Wait(); foreach (var connection in ServerConnections.CONNECTIONS) { ServerConnections.Remove(connection.Value); } }