Exemplo n.º 1
0
        void OnConnectGateServer(object sender, EventArgs e)
        {
            Debug.Log("~~~~~~~~~~~~");
            R2C_Login loginResult = sender as R2C_Login;

            if (loginResult == null)
            {
                return;
            }
            NetworkComponent      network = GameEntry.Network;
            INetworkChannelHelper helper  = new ET_NetworkChannelHelper();
            INetworkChannel       nc      = network.CreateNetworkChannel("CG_TC", helper);

            nc.HeartBeatInterval = 0f;

            IPEndPoint ipPoint = NetworkHelper.ToIPEndPoint(loginResult.Address);

            nc.Connect(ipPoint.Address, ipPoint.Port, loginResult);
        }
    protected internal override void OnEnter(IFsm <IProcedureManager> procedureOwner)
    {
        base.OnEnter(procedureOwner);

        // 获取框架事件组件
        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", ServiceType.Tcp, m_NetworkChannelHelper);

        // 连接服务器
        m_Channel.Connect(IPAddress.Parse("127.0.0.1"), 8098);
    }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    /// <summary>
    /// 创建网络频道
    /// </summary>
    /// <param name="networkComponent"></param>
    /// <param name="channelName"></param>
    public static void CreateNetworkChannel(this NetworkComponent networkComponent, string channelName)
    {
        NetworkChannelHelper helper = new NetworkChannelHelper();

        NetworkExtension.GameChannel = networkComponent.CreateNetworkChannel(channelName, helper);
    }