예제 #1
0
        public NetworkPacketSender(TcpChnl tcpChnl)
        {
            this.tcpChnl    = tcpChnl;
            _tempSendBuffer = new Queue <byte[]>();

            m_headerBytes = BitConverter.GetBytes(NetDefine.TCP_HEADER);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(m_headerBytes);
            }
        }
예제 #2
0
    // 取包 推送给业务层处理
    private bool HandleTcpPacket()
    {
        if (TcpChnl.State != EConnetState.EConneted)
        {
            return(false);
        }
        PacketTuple <IMessage> message = TcpChnl.TryGetRecvedMessage();

        if (message == null)
        {
            return(false);
        }
        return(_broadcastHelp.HandleTcpPacket(message));
    }
예제 #3
0
    public void OnInit()
    {
        _broadcastHelp = new BroadcastHelp();
        //可以写在对应频道 也可以
        _netThread = new Thread(RunAsync);
        _netThread.Start();

        nets = new Dictionary <ENetType, Ichnl>
        {
            { ENetType.UDP, UdpChnl = new UdpChnl() }, { ENetType.TCP, TcpChnl = new TcpChnl() }
        };

#if UNITY_EDITOR
        UnityEditor.EditorApplication.playModeStateChanged -= OnEditorPlayModeChanged;
        UnityEditor.EditorApplication.playModeStateChanged += OnEditorPlayModeChanged;
#endif
    }
예제 #4
0
 /// <summary>
 /// 发送消息
 /// </summary>
 public void SendMessage(short id, IMessage message)
 {
     TcpChnl.SendMessage(id, message);
 }
예제 #5
0
 /// <summary>
 /// 建立TCP连接
 /// </summary>
 public void Connect(string ip, int port)
 {
     TcpChnl.Connect(ip, port);
 }
예제 #6
0
 public void OnRelease()
 {
     _netThread?.Abort();
     TcpChnl.Dispose();
 }
예제 #7
0
 /// <summary>
 /// 关闭一下 TCP连接
 /// </summary>
 public void Close()
 {
     TcpChnl.DisConnect();
 }