Ejemplo n.º 1
0
 /// <summary>
 /// 构造函数,Connect
 /// </summary>
 /// <param name="socket">Socket</param>
 /// <param name="netService">网络服务</param>
 /// <param name="connectConv">网络连接Conv</param>
 public KcpChannel(Socket socket, IPEndPoint endPoint, ANetService netService, uint connectConv) : base(netService, connectConv)
 {
     this.RemoteEndPoint = endPoint;
     this.NetSocket      = socket;
     RecvParser          = new PacketParser();
     SendParser          = new PacketParser();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 构造函数,Accept
 /// </summary>
 /// <param name="endPoint">IP/端口</param>
 /// <param name="socket">TCP socket类</param>
 /// <param name="netService">通讯网络服务对象</param>
 public TcpChannel(IPEndPoint endPoint, Socket socket, ANetService netService) : base(netService)
 {
     this.LocalEndPoint      = endPoint;
     this.NetSocket          = socket;
     this.inArgs             = new SocketAsyncEventArgs();
     this.outArgs            = new SocketAsyncEventArgs();
     this.inArgs.Completed  += OnComplete;
     this.outArgs.Completed += OnComplete;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 开始监听并接受客户端连接
 /// </summary>
 /// <param name="endPoint"></param>
 public void Accept()
 {
     if (this.protocalType == ProtocalType.Tcp)
     {
         this.netService = new TcpService(this.endPoint, this, NetServiceType.Server);
     }
     else if (this.protocalType == ProtocalType.Kcp)
     {
         this.netService = new KcpService(this.endPoint, this, NetServiceType.Server);
     }
     this.netService.Accept();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 连接服务器
 /// </summary>
 /// <param name="endPoint"></param>
 /// <returns></returns>
 public ANetChannel Connect()
 {
     if (this.protocalType == ProtocalType.Tcp)
     {
         this.netService = new TcpService(this.endPoint, this, NetServiceType.Client);
     }
     else if (this.protocalType == ProtocalType.Kcp)
     {
         this.netService = new KcpService(this.endPoint, this, NetServiceType.Client);
     }
     clientChannel = this.netService.Connect();
     return(clientChannel);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="netService">网络通讯服务对象</param>
 /// <param name="conv">KCP连接确认号Conv</param>
 public ANetChannel(ANetService netService, uint conv)
 {
     this.netService = netService;
     Id = conv;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="netService">网络通讯服务对象</param>
 public ANetChannel(ANetService netService)
 {
     this.netService = netService;
     Id = ChannelIdCreator.CreateId();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 创建消息处理类
        /// </summary>
        /// <param name="channel">通讯管道对象</param>
        /// <param name="netService">网络服务对象</param>
        /// <returns></returns>
        public static IEnumerable <IMessageHandler> CreateHandlers(ANetChannel channel, ANetService netService)
        {
            var handlers = new List <IMessageHandler>();

            foreach (var type in types)
            {
                var handler = (IMessageHandler)Activator.CreateInstance(type);
                handler.Channel    = channel;
                handler.NetService = netService;
                channel.OnReceive += handler.DoReceive;
                handlers.Add(handler);
            }
            return(handlers);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 构造函数,Connect
 /// </summary>
 /// <param name="endPoint">Ip/端口</param>
 /// <param name="netService">通讯网络服务对象</param>
 public TcpChannel(IPEndPoint endPoint, ANetService netService) : base(netService)
 {
     this.RemoteEndPoint = endPoint;
 }