ConnectEndPoint() public static method

public static ConnectEndPoint ( int hostId, EndPoint endPoint, int exceptionConnectionId, byte &error ) : int
hostId int
endPoint System.Net.EndPoint
exceptionConnectionId int
error byte
return int
コード例 #1
0
        public void Connect(EndPoint secureTunnelEndPoint)
        {
            PrepareForConnect();
            if (LogFilter.logDebug)
            {
                Debug.Log("Client Connect to remoteSockAddr");
            }
            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: null endpoint passed in");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            string fullName = secureTunnelEndPoint.GetType().FullName;

            if (fullName == "System.Net.IPEndPoint")
            {
                IPEndPoint iPEndPoint = (IPEndPoint)secureTunnelEndPoint;
                Connect(iPEndPoint.Address.ToString(), iPEndPoint.Port);
                return;
            }
            if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint")
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint)");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            byte error = 0;

            m_RemoteEndPoint = secureTunnelEndPoint;
            m_AsyncConnect   = ConnectState.Connecting;
            try
            {
                m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error);
            }
            catch (Exception arg)
            {
                Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + arg);
            }
            if (m_ClientConnectionId == 0 && LogFilter.logError)
            {
                Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")");
            }
            m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
            m_Connection.SetHandlers(m_MessageHandlers);
            m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
        }
コード例 #2
0
        public void Connect(EndPoint secureTunnelEndPoint)
        {
            bool usePlatformSpecificProtocols = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint);

            this.PrepareForConnect(usePlatformSpecificProtocols);
            if (LogFilter.logDebug)
            {
                Debug.Log("Client Connect to remoteSockAddr");
            }
            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: null endpoint passed in");
                }
                this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
            }
            else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
            }
            else
            {
                string fullName = secureTunnelEndPoint.GetType().FullName;
                if (fullName == "System.Net.IPEndPoint")
                {
                    IPEndPoint ipendPoint = (IPEndPoint)secureTunnelEndPoint;
                    this.Connect(ipendPoint.Address.ToString(), ipendPoint.Port);
                }
                else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint" && fullName != "UnityEngine.PSVita.SceEndPoint")
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
                    }
                    this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                }
                else
                {
                    byte b = 0;
                    this.m_RemoteEndPoint = secureTunnelEndPoint;
                    this.m_AsyncConnect   = NetworkClient.ConnectState.Connecting;
                    try
                    {
                        this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out b);
                    }
                    catch (Exception arg)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + arg);
                        }
                        this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                        return;
                    }
                    if (this.m_ClientConnectionId == 0)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Unable to connect to EndPoint (" + b + ")");
                        }
                        this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                    }
                    else
                    {
                        this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass);
                        this.m_Connection.SetHandlers(this.m_MessageHandlers);
                        this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology);
                    }
                }
            }
        }
コード例 #3
0
        public bool ReconnectToNewHost(EndPoint secureTunnelEndPoint)
        {
            bool result;

            if (!NetworkClient.active)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - NetworkClient must be active");
                }
                result = false;
            }
            else if (this.m_Connection == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - no old connection exists");
                }
                result = false;
            }
            else
            {
                if (LogFilter.logInfo)
                {
                    Debug.Log("NetworkClient Reconnect to remoteSockAddr");
                }
                ClientScene.HandleClientDisconnect(this.m_Connection);
                ClientScene.ClearLocalPlayers();
                this.m_Connection.Disconnect();
                this.m_Connection = null;
                this.m_ClientId   = NetworkTransport.AddHost(this.m_HostTopology, this.m_HostPort);
                if (secureTunnelEndPoint == null)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Reconnect failed: null endpoint passed in");
                    }
                    this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                    result = false;
                }
                else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                    }
                    this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                    result = false;
                }
                else
                {
                    string fullName = secureTunnelEndPoint.GetType().FullName;
                    if (fullName == "System.Net.IPEndPoint")
                    {
                        IPEndPoint ipendPoint = (IPEndPoint)secureTunnelEndPoint;
                        this.Connect(ipendPoint.Address.ToString(), ipendPoint.Port);
                        result = (this.m_AsyncConnect != NetworkClient.ConnectState.Failed);
                    }
                    else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint")
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
                        }
                        this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                        result = false;
                    }
                    else
                    {
                        byte b = 0;
                        this.m_RemoteEndPoint = secureTunnelEndPoint;
                        this.m_AsyncConnect   = NetworkClient.ConnectState.Connecting;
                        try
                        {
                            this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out b);
                        }
                        catch (Exception arg)
                        {
                            if (LogFilter.logError)
                            {
                                Debug.LogError("Reconnect failed: Exception when trying to connect to EndPoint: " + arg);
                            }
                            this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                            return(false);
                        }
                        if (this.m_ClientConnectionId == 0)
                        {
                            if (LogFilter.logError)
                            {
                                Debug.LogError("Reconnect failed: Unable to connect to EndPoint (" + b + ")");
                            }
                            this.m_AsyncConnect = NetworkClient.ConnectState.Failed;
                            result = false;
                        }
                        else
                        {
                            this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass);
                            this.m_Connection.SetHandlers(this.m_MessageHandlers);
                            this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        public void Connect(EndPoint secureTunnelEndPoint)
        {
            bool usePlatformSpecificProtocols = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint);

            PrepareForConnect(usePlatformSpecificProtocols);

            if (LogFilter.logDebug)
            {
                Debug.Log("Client Connect to remoteSockAddr");
            }

            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: null endpoint passed in");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }

            // Make sure it's either IPv4 or IPv6
            if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }

            // Make sure it's an Endpoint we know what to do with
            string endPointType = secureTunnelEndPoint.GetType().FullName;

            if (endPointType == "System.Net.IPEndPoint")
            {
                IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint;
                Connect(tmp.Address.ToString(), tmp.Port);
                return;
            }
            if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint"))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }

            byte error = 0;

            // regular non-relay connect
            m_RemoteEndPoint = secureTunnelEndPoint;
            m_AsyncConnect   = ConnectState.Connecting;

            try
            {
                m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error);
            }
            catch (Exception ex)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + ex);
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            if (m_ClientConnectionId == 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }

            m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
            m_Connection.SetHandlers(m_MessageHandlers);
            m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
        }
コード例 #5
0
        public bool ReconnectToNewHost(EndPoint secureTunnelEndPoint)
        {
            if (!NetworkClient.active)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - NetworkClient must be active");
                }
                return(false);
            }

            if (m_Connection == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - no old connection exists");
                }
                return(false);
            }

            if (LogFilter.logInfo)
            {
                Debug.Log("NetworkClient Reconnect to remoteSockAddr");
            }

            ClientScene.HandleClientDisconnect(m_Connection);
            ClientScene.ClearLocalPlayers();

            m_Connection.Disconnect();
            m_Connection = null;
            m_ClientId   = NetworkTransport.AddHost(m_HostTopology, 0);

            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect failed: null endpoint passed in");
                }
                m_AsyncConnect = ConnectState.Failed;
                return(false);
            }

            // Make sure it's either IPv4 or IPv6
            if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                m_AsyncConnect = ConnectState.Failed;
                return(false);
            }

            // Make sure it's an Endpoint we know what to do with
            string endPointType = secureTunnelEndPoint.GetType().FullName;

            if (endPointType == "System.Net.IPEndPoint")
            {
                IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint;
                Connect(tmp.Address.ToString(), tmp.Port);
                return(m_AsyncConnect != ConnectState.Failed);
            }
            if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint"))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
                }
                m_AsyncConnect = ConnectState.Failed;
                return(false);
            }

            byte error = 0;

            // regular non-relay connect
            m_RemoteEndPoint = secureTunnelEndPoint;
            m_AsyncConnect   = ConnectState.Connecting;

            try
            {
                m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error);
            }
            catch (Exception ex)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect failed: Exception when trying to connect to EndPoint: " + ex);
                }
                m_AsyncConnect = ConnectState.Failed;
                return(false);
            }
            if (m_ClientConnectionId == 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect failed: Unable to connect to EndPoint (" + error + ")");
                }
                m_AsyncConnect = ConnectState.Failed;
                return(false);
            }

            m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
            m_Connection.SetHandlers(m_MessageHandlers);
            m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
            return(true);
        }
コード例 #6
0
 public int ConnectEndPoint(int hostId, EndPoint endPoint, int specialConnectionId, out byte error)
 {
     return(NetworkTransport.ConnectEndPoint(hostId, endPoint, specialConnectionId, out error));
 }