コード例 #1
0
 public bool TryGetConnection(out Connection con, Message msg, IPEndPoint endPoint)
 {
     lock (_connections)
     {
         if (msg.Header.ConnectionToken != null &&
             _connections.ContainsKey(msg.Header.ConnectionToken))
         {
             con = _connections[msg.Header.ConnectionToken];
             if (con.EndPoint == null)
             {
                 con.EndPoint = endPoint;
             }
             return(true);
         }
         if (msg.Header.Type == (short)MessageType.Handshake)
         {
             con = new Connection(endPoint);
             _connections.Add(con.Token, con);
             if (HandshakeRecieved != null)
             {
                 HandshakeRecieved.Invoke(con);
             }
             return(true);
         }
         if (msg.Header.Type == (short)MessageType.Token)
         {
             con = new Connection(endPoint, msg.ConnectionToken);
             _connections.Add(con.Token, con);
             return(true);
         }
     }
     con = null;
     return(false);
 }
コード例 #2
0
 public bool TryGetConnection(out Connection con, Message msg, IPEndPoint endPoint)
 {
     lock (_connections) {
         if (msg.Header.ConnectionToken != null)
         {
             if (!_connections.ContainsKey(msg.ConnectionToken))
             {
                 Console.WriteLine("Create new connecton");
                 _connections[msg.ConnectionToken] = new Connection(endPoint, msg.ConnectionToken);
             }
             con = _connections[msg.Header.ConnectionToken];
             if (con.EndPoint == null)
             {
                 con.EndPoint = endPoint;
             }
             return(true);
         }
     }
     // ReSharper disable once ConvertIfStatementToSwitchStatement
     if (msg.Header.Type == (short)MessageType.Handshake)
     {
         con = new Connection(endPoint);
         _connections.Add(con.Token, con);
         // ReSharper disable once UseNullPropagation
         if (HandshakeRecieved != null)
         {
             HandshakeRecieved.Invoke(con);
         }
         return(true);
     }
     else if (msg.Header.Type == (short)MessageType.Token)
     {
         con = new Connection(endPoint, msg.ConnectionToken);
         _connections.Add(con.Token, con);
         return(true);
     }
     con = null;
     return(false);
 }