Connect() public method

public Connect ( EndPoint secureTunnelEndPoint ) : void
secureTunnelEndPoint System.Net.EndPoint
return void
コード例 #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);
        }
コード例 #2
0
 public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
 {
     matchInfo = info;
     if (m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     isNetworkActive = true;
     client          = new NetworkClient();
     if (config != null)
     {
         client.Configure(config, 1);
     }
     else if (m_CustomConfig && m_ConnectionConfig != null)
     {
         m_ConnectionConfig.Channels.Clear();
         foreach (QosType channel in m_Channels)
         {
             m_ConnectionConfig.AddChannel(channel);
         }
         client.Configure(m_ConnectionConfig, m_MaxConnections);
     }
     RegisterClientMessages(client);
     if (matchInfo != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient match: " + matchInfo);
         }
         client.Connect(matchInfo);
     }
     else if (m_EndPoint != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient using provided SecureTunnel");
         }
         client.Connect(m_EndPoint);
     }
     else
     {
         if (string.IsNullOrEmpty(m_NetworkAddress))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Must set the Network Address field in the manager");
             }
             return(null);
         }
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
         }
         if (m_UseSimulator)
         {
             client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage);
         }
         else
         {
             client.Connect(m_NetworkAddress, m_NetworkPort);
         }
     }
     OnStartClient(client);
     s_Address = m_NetworkAddress;
     return(client);
 }
コード例 #3
0
        public NetworkClient StartClient(ConnectionConfig config, int hostPort)
        {
            InitializeSingleton();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client          = new NetworkClient();
            client.hostPort = hostPort;

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    for (int i = 0; i < m_Channels.Count; i++)
                    {
                        m_ConnectionConfig.AddChannel(m_Channels[i]);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                client.Connect(m_NetworkAddress, m_NetworkPort);
            }

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
コード例 #4
0
        public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
        {
            InitializeSingleton();

            matchInfo = info;
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client = new NetworkClient();

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    foreach (var c in m_Channels)
                    {
                        m_ConnectionConfig.AddChannel(c);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (matchInfo != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient match: " + matchInfo);
                }
                client.Connect(matchInfo);
            }
            else if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                if (m_UseSimulator)
                {
                    client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage);
                }
                else
                {
                    client.Connect(m_NetworkAddress, m_NetworkPort);
                }
            }

#if ENABLE_UNET_HOST_MIGRATION
            if (m_MigrationManager != null)
            {
                m_MigrationManager.Initialize(client, matchInfo);
            }
#endif

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
コード例 #5
0
ファイル: Client.cs プロジェクト: Johannesolof/DoDGame
		// CONSTRUCTOR
		public Client(NetworkingInfo netinfo)
		{
			networkingInfo = netinfo;
			if(networkingInfo.port == -1) networkingInfo.port = NetworkingInfo.defaultPort;
			if(networkingInfo.address == "") networkingInfo.address = NetworkingInfo.defaultAddress;
			// TODO: Add some kind of DNS pre check for IP?

			connectedPlayers = new List<Player>();

			config = new ConnectionConfig();
			Channels.priority = config.AddChannel(QosType.AllCostDelivery);
			Channels.reliable = config.AddChannel(QosType.ReliableSequenced);
			Channels.unreliable = config.AddChannel(QosType.UnreliableSequenced);
			Channels.fragmented = config.AddChannel(QosType.ReliableFragmented);
			Channels.update = config.AddChannel(QosType.StateUpdate);
			hostconfig = new HostTopology(config, maxConcurrentConnectedUsers);

			if(networkingInfo.isServer)
			{
				myClient = ClientScene.ConnectLocalServer();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);
			}
			else
			{
				myClient = new NetworkClient();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Error, ConnectionError);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);

				common.printConsole (tag, "Setup complete", true);

				myClient.Connect(networkingInfo.address, networkingInfo.port);
				common.printConsole (tag, "Connecting to " + networkingInfo.address + ":" + networkingInfo.port, true);
			}
		}