Пример #1
0
    private void ConnectServer()
    {
        if (m_CustomNetworkChannelHelper != null)
        {
            m_CustomNetworkChannelHelper.Shutdown();
        }
        if (m_NetworkChannel != null)
        {
            m_NetworkChannel.Close();
        }
        m_CustomNetworkChannelHelper = new ET_NetworkChannelHelper();
        m_NetworkChannel             = GameEntry.Network.CreateNetworkChannel("tcp" + m_ConnectTime++, GameFramework.Network.ServiceType.TcpWithSyncReceive, m_CustomNetworkChannelHelper);
        IPAddress iPAddress = IPAddress.Parse("192.168.31.32");

        //IPAddress iPAddress = IPAddress.Parse("129.28.170.32");
        m_NetworkChannel.Connect(iPAddress, SrvCfg.srvPort);
        //StartCoroutine(client.CheckNet());
    }
Пример #2
0
        public static void InitNetWork(string host, int port)
        {
            // 启动服务器(服务端的代码随便找随便改的,大家可以忽略,假设有个服务端就行了)
            //Demo8_SocketServer.Start();
            // 获取框架网络组件
            NetworkComponent Network = UnityGameFramework.Runtime.GameEntry.GetComponent <NetworkComponent>();


            // 获取框架事件组件
            //EventComponent Event = UnityGameFramework.Runtime.GameEntry.GetComponent<EventComponent>();

            // Event.Subscribe(NetworkConnectedEventArgs.EventId, OnConnected);

            // 创建频道

            m_NetworkChannelHelper = new NetworkChannelHelper();

            m_Channel = Network.CreateNetworkChannel("testName", m_NetworkChannelHelper);

            // 连接服务器
            m_Channel.Connect(IPAddress.Parse(host), port);
        }
Пример #3
0
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);

        // 启动服务器(服务端的代码随便找随便改的,大家可以忽略,假设有个服务端就行了)
        Demo8_SocketServer.Start();

        // 获取框架事件组件
        EventComponent Event
            = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent> ();

        Event.Subscribe(NetworkConnectedEventArgs.EventId, OnConnected);

        // 获取框架网络组件
        NetworkComponent Network
            = UnityGameFramework.Runtime.GameEntry.GetComponent <NetworkComponent> ();

        // 创建频道
        m_NetworkChannelHelper = new NetworkChannelHelper();
        m_Channel = Network.CreateNetworkChannel("testName", m_NetworkChannelHelper);

        // 连接服务器
        m_Channel.Connect(IPAddress.Parse("127.0.0.1"), 8098);
    }