Exemplo n.º 1
0
        public WChannel(WebSocket m_WebSocket, AService service) : base(service, ChannelType.Connect)
        {
            this.m_WebSocket = m_WebSocket;

            this.m_MemoryStream = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);
            this.m_RecvStream   = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);

            m_ChannelState = ChannelState.EDisConnected;
        }
Exemplo n.º 2
0
        protected AChannel(AService service, ChannelType channelType)
        {
            this.Id          = IdGenerater.GenerateId();
            this.ChannelType = channelType;
            this.m_Service   = service;
            m_IsDisposed     = false;
            m_ChannelState   = ChannelState.EConnecting;

            this.m_LastRecvTime = service.TimeNow;
            this.m_CreateTime   = service.TimeNow;
        }
Exemplo n.º 3
0
        public WChannel(HttpListenerWebSocketContext m_WebSocketContext, AService service) : base(service, ChannelType.Accept)
        {
            this.WebSocketContext = m_WebSocketContext;

            this.m_WebSocket = m_WebSocketContext.WebSocket;

            this.m_MemoryStream = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);
            this.m_RecvStream   = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);
            m_ChannelState      = ChannelState.EConnected;
            Start();
        }
Exemplo n.º 4
0
        //public IMessageDispatcher MessageDispatcher { get; set; }

        /*
         * public NetworkRoot(NetworkProtocol networkProtocol, ChannelType channelType,string StrIpEndPoint)
         * {
         *  m_NetworkProtocol = networkProtocol;
         *  m_ChannelType = channelType;
         *  m_StrIpEndPoint = StrIpEndPoint;
         * }*/



        public override bool Init()
        {
            if (m_ChannelType == ChannelType.Connect)
            {
                switch (m_NetworkProtocol)
                {
                case NetworkProtocol.KCP:
                    this.m_AService = new KService();
                    break;

                case NetworkProtocol.TCP:
                    this.m_AService = new TService(Packet.PacketSizeLength2);
                    break;

                case NetworkProtocol.WebSocket:
                    this.m_AService = new WService();
                    break;
                }
            }
            else
            {
                try
                {
                    IPEndPoint ipEndPoint;
                    switch (m_NetworkProtocol)
                    {
                    case NetworkProtocol.KCP:
                        ipEndPoint      = NetHelper.ToIPEndPoint(m_StrIpEndPoint);
                        this.m_AService = new KService(ipEndPoint, this.OnAccept);
                        break;

                    case NetworkProtocol.TCP:
                        ipEndPoint      = NetHelper.ToIPEndPoint(m_StrIpEndPoint);
                        this.m_AService = new TService(Packet.PacketSizeLength2, ipEndPoint, this.OnAccept);
                        break;

                    case NetworkProtocol.WebSocket:
                        string[] prefixs = m_StrIpEndPoint.Split(';');
                        this.m_AService = new WService(prefixs, this.OnAccept);
                        break;
                    }
                    this.m_AService.DisConnectedCallback += OnDisConnected;
                }
                catch (Exception e)
                {
                    throw new Exception($"NetworkComponent Awake Error {m_StrIpEndPoint}", e);
                }
            }

            return(base.Init());
        }