/// <summary> /// Returns a connection based on the id, otherwise it returns a null object. /// </summary> public ConnectionCore GetConnectionByID(int id) { if (Connections.ContainsKey(id)) { ConnectionCore connection = Connections[id]; return(connection); } return(null); }
/// <summary> /// Accepts a connection. /// </summary> private void AcceptConnection(IAsyncResult ar) { try { Socket handler = Socket.EndAccept(ar); ConnectionCore connection = new ConnectionCore(LastClientID++, handler, this); Connections.TryAdd(connection.ID, connection); } catch (Exception e) { ServerLogger.Error(e.Message); } finally { if (Connected) { Socket.BeginAccept(AcceptConnection, null); } } }