object System.ICloneable.Clone() { Session newSession = new Session(_cliSock); newSession.Datagram = _datagram; newSession.TypeOfExit = _exitType; return newSession; }
/// <summary> /// Establish Tcp连接后处理过程 /// </summary> /// <param name="iar">Async Socket</param> protected virtual void Connected(IAsyncResult iar) { try { Socket socket = null; socket = (Socket)iar.AsyncState; socket.EndConnect(iar); //创建新的会话 _session = new Session(socket); _isConnected = true; //触发连接Establish 事件 if (ConnectedServer != null) { ConnectedServer(this, new NetEventArgs(_session)); } //Establish 连接后应该立即接收数据 _session.ClientSocket.BeginReceive(_recvDataBuffer, 0, DefaultBufferSize, SocketFlags.None, new AsyncCallback(RecvData), socket); } catch (Exception e) { Console.WriteLine(e.StackTrace); DateTime now = DateTime.Now; LogUtil.Error(" Send === Exception " + " " + now.ToLongTimeString() + " H "+now.Hour + " m " + now.Minute + " s " + now.Second + " ms " + now.Millisecond); LogUtil.Error(" "+e.StackTrace); timeOut = true; } }
/// <summary> /// Constructor /// </summary> /// <param name="client">客户端会话</param> public NetEventArgs(Session client) { if (null == client) { throw (new ArgumentNullException()); } _client = client; }
/// <summary> /// Close连接 /// </summary> public virtual void Close() { if (!_isConnected) { return; } _session.Close(); _session = null; _isConnected = false; timeOut = true; }