/// <summary> /// 断开连接事件调用 /// </summary> internal virtual void OnDisconnect(SocketEngine _socket = null) { if (this.OnDisconnectEvent != null) { this.OnDisconnectEvent(_socket); } }
/// <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; }
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); }
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; }
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); }