/// <summary> /// TCPs the or UDP connection closed. /// </summary> /// <param name="closeReason">The close reason.</param> /// <param name="connection">The connection.</param> private void tcpOrUdpConnectionClosed(CloseReason closeReason, Connection connection) { if(connection.GetType().Equals(typeof(TcpConnection))) { //If it is an tcp connection we have to close all the udp connections. this[(TcpConnection)connection].ForEach(c => c.Close(closeReason)); connections.Remove((TcpConnection)connection); } else { //Remove the udp connection from the list. this[this[(UdpConnection)connection]].Remove((UdpConnection)connection); } if (connectionLost != null && connectionLost.GetInvocationList().Length > 0 && connection.GetType().Equals(typeof(TcpConnection))) connectionLost(connection, ConnectionType.TCP, closeReason); else if (connectionLost != null && connectionLost.GetInvocationList().Length > 0 && connection.GetType().Equals(typeof(UdpConnection))) connectionLost(connection, ConnectionType.UDP, closeReason); }
private void connectionEstablished(Connection connection, ConnectionType type) { Console.WriteLine("Connection established!"); Console.WriteLine($"{connection.GetType()} connected on port {connection.IPLocalEndPoint.Port}"); connection.RegisterPacketHandler(typeof(TalkPacket), messageReceived); }