UnityEngine.Networking.NetworkClient.Connect C# (CSharp) Method

Connect() public method

public Connect ( EndPoint secureTunnelEndPoint ) : void
secureTunnelEndPoint System.Net.EndPoint
return void
        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 = 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 = ConnectState.Failed;
            }
            else
            {
                string fullName = secureTunnelEndPoint.GetType().FullName;
                if (fullName == "System.Net.IPEndPoint")
                {
                    IPEndPoint point = (IPEndPoint) secureTunnelEndPoint;
                    this.Connect(point.Address.ToString(), point.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 = ConnectState.Failed;
                }
                else
                {
                    byte error = 0;
                    this.m_RemoteEndPoint = secureTunnelEndPoint;
                    this.m_AsyncConnect = ConnectState.Connecting;
                    try
                    {
                        this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out error);
                    }
                    catch (Exception exception)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + exception);
                        }
                        this.m_AsyncConnect = ConnectState.Failed;
                        return;
                    }
                    if (this.m_ClientConnectionId == 0)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")");
                        }
                        this.m_AsyncConnect = 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);
                    }
                }
            }
        }

Same methods

NetworkClient::Connect ( MatchInfo matchInfo ) : void
NetworkClient::Connect ( string serverIp, int serverPort ) : void

Usage Example

コード例 #1
0
        // Create a client and connect to the server port
        public void SetupClient()
        {
            ClientScene.RegisterPrefab(Prefab);

            client = new NetworkClient();

            client.RegisterHandler(MsgType.Connect, OnConnected);
            client.Connect("127.0.0.1", 4444);
        }
All Usage Examples Of UnityEngine.Networking.NetworkClient::Connect