예제 #1
0
 public NetworkSession(NetworkClient rNet, AChannel rChannel)
 {
     this.Id       = mIdGenerator++;
     this.Error    = 0;
     this.mChannel = rChannel;
     this.mRequestCallback.Clear();
     this.StartRecv();
 }
예제 #2
0
        public virtual async Task <NetworkSession> Accept()
        {
            AChannel rChannel = await this.mService.AcceptChannel();

            NetworkSession rSession = new NetworkSession(this, rChannel);

            rSession.Parent         = this;
            rChannel.ErrorCallback += (c, e) =>
            {
                rSession.Error = e;
                this.Remove(rSession.Id);
            };
            this.mSessions.Add(rSession.Id, rSession);
            return(rSession);
        }
예제 #3
0
 /// <summary>
 /// 创建一个新Session
 /// </summary>
 public virtual NetworkSession Create(IPEndPoint rIpEndPoint)
 {
     try
     {
         AChannel       rChannel = this.mService.ConnectChannel(rIpEndPoint);
         NetworkSession rSession = new NetworkSession(this, rChannel);
         rSession.Parent         = this;
         rChannel.ErrorCallback += (c, e) =>
         {
             rSession.Error = e;
             this.Remove(rSession.Id);
         };
         this.mSessions.Add(rSession.Id, rSession);
         return(rSession);
     }
     catch (Exception e)
     {
         Debug.LogError(e);
         return(null);
     }
 }