//Create new connection if none is found
        public SocketConnection CreateConnection(NetPeer peer, SocketConnectionInfo connInfo)
        {
            var newConnection = GetConnection(peer);

            if (newConnection == null)
            {
                AddConnection(connInfo, out newConnection);
            }
            return(newConnection);
        }
 public bool UpdateConnection(NetPeer peer, SocketConnectionInfo connInfo, out SocketConnection updatedConnection)
 {
     updatedConnection = GetConnection(peer);
     if (updatedConnection != null)
     {
         updatedConnection.UpdateConnectionInfo(connInfo);
         SocketLog.Info("Sucessfully updated connection {0} with new connection information.", peer.EndPoint);
         return(true);
     }
     SocketLog.Error("Failed to update connection {0} with new connection information. Connection not found in Socket Interface!", peer.EndPoint);
     return(false);
 }
 public bool AddPendingConnection(SocketConnectionInfo connInfo, out SocketConnection potentialSocketConnection)
 {
     potentialSocketConnection = new SocketConnection(this, connInfo);
     if (!PendingConnections.Contains(potentialSocketConnection))
     {
         PendingConnections.Add(potentialSocketConnection);
         SocketLog.Info("Connection {0}:{1} currently pending approval | ID: {2}", potentialSocketConnection.ConnectionInfo.Address, potentialSocketConnection.ConnectionInfo.Port, potentialSocketConnection.ConnectionInfo.Peer.ConnectId);
         return(true);
     }
     SocketLog.Error("Failed to place connection {0}:{1} | ID: {2} in pending queue.", potentialSocketConnection.ConnectionInfo.Address, potentialSocketConnection.ConnectionInfo.Port, potentialSocketConnection.ConnectionInfo.Peer.ConnectId);
     potentialSocketConnection = null;
     return(false);
 }
 /// <summary>
 /// Adds a connection to the list of connections on this socket interface
 /// </summary>
 /// <param name="newSocketConnection">If successful, the newly created connection</param>
 /// <returns>If connection is added successfully, true, if not false - also newSocketConnection will be null</returns>
 public bool AddConnection(SocketConnectionInfo connInfo, out SocketConnection newSocketConnection)
 {
     newSocketConnection = new SocketConnection(this, connInfo);
     if (!Connections.Contains(newSocketConnection))
     {
         Connections.Add(newSocketConnection);
         SocketLog.Info("Added connection {0}:{1}", newSocketConnection.ConnectionInfo.Address, newSocketConnection.ConnectionInfo.Port);
         return(true);
     }
     SocketLog.Error("Failed to add connection {0}:{1} from {2}", connInfo.Peer.EndPoint.Host, connInfo.Peer.EndPoint.Port, connInfo.Peer.ConnectId);
     newSocketConnection = null;
     return(false);
 }
Exemple #5
0
        public SocketConnection(SocketInterface socketInterface, SocketConnectionInfo connectionInfo)
        {
            networkRtt = defaultNetworkPing;
            aliasedRtt = defaultAliasedPing;

            creationTime = Time.time;

            this.connectionInfo  = connectionInfo;
            this.socketInterface = socketInterface;

            SetMode();

            endPoint = new IPEndPoint(IPAddress.Parse(connectionInfo.Address), connectionInfo.Port);
        }
        public bool Connect(SocketEndPoint endPoint, IMessageRider token)
        {
            //Checks before preceeding
            if (IsHost)
            {
                SocketLog.Error("Cannot connect when we are a host!");
                return(false);
            }
            if (connected)
            {
                SocketLog.Error("Cannot connect when we are already connected!");
                return(false);
            }
            if (connecting)
            {
                SocketLog.Error("Cannot connect when we are already connecting!");
                return(false);
            }

            client.Connect(endPoint.address, endPoint.port);

            //Set Address and Port
            address = endPoint.address;
            port    = endPoint.port;
            //Set the values of this connection
            SetConnectionValues(endPoint.address, endPoint.port);
            //Create a new instance of connection info
            SocketConnectionInfo info = new SocketConnectionInfo(address, port);
            //Initialize a new connection
            SocketConnection conn;

            //Add a connection
            AddConnection(info, out conn);
            //Cache our connect token to be sent once the communication lines have been established
            conn.ConnectToken = WriteToken(token, NetworkMsg.Connect);
            //Log our succeeded attempt
            SocketLog.Info("Connection Attempt to: {0} : {1}", endPoint.address, endPoint.port);
            //Set connecting
            connecting = true;

            return(true);
        }
Exemple #7
0
 /// <summary>
 /// Replaces the given connection info with the new
 /// </summary>
 /// <param name="info">The new info to replace the old with</param>
 public void UpdateConnectionInfo(SocketConnectionInfo info)
 {
     connectionInfo = info;
 }