Ejemplo n.º 1
0
 /// <summary>
 /// 断开连接事件调用
 /// </summary>
 internal virtual void OnDisconnect(SocketEngine _socket = null)
 {
     if (this.OnDisconnectEvent != null)
     {
         this.OnDisconnectEvent(_socket);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="_socketEngine">引擎对象</param>
 /// <param name="_socket">Socket对象</param>
 public SocketSession(SocketEngine _socketEngine, int _index)
 {
     this.Index                          = _index;
     this.LastOperationTime              = DateTime.UtcNow;
     this.Paraments                      = new Dictionary <string, object>();
     this.SocketAsyncEventArgs           = new SocketAsyncEventArgs();
     this.SocketAsyncEventArgs.UserToken = this;
     this.SocketEngine                   = _socketEngine;
     this.Status                         = SocketSessionStatus.Pending;
 }
Ejemplo n.º 3
0
        public void SendFirstPackage(SocketEngine _socket)
        {
            Random _random = new Random(RandomPlus.RandomSeed);

            this.socketRxKey    = _random.Next(10000000, 100000000).ToString();
            this.socketChecksum = _random.Next(10000000, 100000000).ToString();

            JObject _json = new JObject();

            _json["code"] = this.Code;
            _json["time"] = DateTimePlus.DateTime2JSTime(DateTime.UtcNow).ToString();
            _json["num"]  = this.socketChecksum;
            _json["key"]  = this.socketRxKey;

            _socket.SendPackage(_json);
        }
Ejemplo n.º 4
0
 protected virtual void Dispose(bool _disposing)
 {
     this.Handshaked = false;
     if (!this.Disposed) // 非托管释放
     {
     }
     if (_disposing) // 托管释放
     {
         this.SocketEngine         = null;
         this.SocketAsyncEventArgs = null;
         this.ReceivedStream.Close();
         this.ReceivedStream.Dispose();
         this.ReceivedStream = null;
         this.Protocol       = null;
         this.Paraments      = null;
     }
     this.Disposed = true;
 }
Ejemplo n.º 5
0
        public bool ReceiveFirstPackage(JObject _json, SocketEngine _socket)
        {
            if (this.socketTxKey != "")
            {
                return(false);
            }

            if (!this.rsa.Verify(this.socketChecksum, _json["check"].Value <string>()))
            {
                this.socketTxKey = "";
                return(true);
            }
            this.socketTxKey = _json["key"].Value <string>();

            JObject _result = new JObject();

            _result["check"] = this.rsa.Sign(_json["num"].Value <string>());

            _socket.SendPackage(_result);
            _socket.Handshaked = true;
            return(true);
        }