/// <summary> /// 连接 /// </summary> /// <param name="address"></param> /// <param name="port"></param> public override void Connect(string address, int port) { this.m_iPort = port; this.m_cDispatch = this.m_cDispatchFactory.Create(this); DummyAcceptManager.GetInstance().Connect(this, this.m_iPort); this.m_cDispatch.OnConnect(); ChangeStatus(SESSION_STATUS.CONNECT_SUCCESS); }
private SESSION_STATUS m_cStatus; //会话状态 #endregion Fields #region Constructors public SeverSession(Socket socket, DispatchFactoryBase dispatchFactory) { this.m_cDispatchFactory = dispatchFactory; this.m_cDispatch = this.m_cDispatchFactory.Create( this ); this.m_cSocket = socket; this.m_cReceiveBuffer = new StreamBuffer(); this.m_cSendBuffer = new StreamBuffer(); this.m_cSendQueue = new NetQueue<PacketBase>(64 * 256); this.m_cSendQueue.Clear(); }
/// <summary> /// 异步连接回调 /// </summary> /// <param name="ar"></param> private void ConnectCallBack(IAsyncResult ar) { try { this.m_cSocket = (Socket)ar.AsyncState; if (this.m_cSocket == null) { //ERROR throw new Exception("Socket connect Failed."); } this.m_cSocket.EndConnect(ar); ChangeStatus(SESSION_STATUS.CONNECT_SUCCESS); this.m_cDispatch = this.m_cDispatchFactory.Create(this); this.m_cDispatch.OnConnect(); Receive(); } catch (Exception e) { WriteFiles.WritFile.Log(LogerType.ERROR, e.StackTrace); DisConnect(); ChangeStatus(SESSION_STATUS.CONNECT_FAILED_CONNECT_ERROR); } }
/// <summary> /// 释放 /// </summary> /// <param name="dispatch"></param> public override void Destory(Dispatch dispatch) { return; }
public abstract Dispatch Create(ISession session); //创建 public abstract void Destory(Dispatch dispatch); //释放
/// <summary> /// 异步连接回调 /// </summary> /// <param name="ar"></param> private void ConnectCallBack(IAsyncResult ar) { try { this.m_cSocket = (Socket)ar.AsyncState; if (this.m_cSocket == null) { //ERROR throw new Exception("Socket connect Failed."); } this.m_cSocket.EndConnect(ar); ChangeStatus(SESSION_STATUS.CONNECT_SUCCESS); this.m_cDispatch = this.m_cDispatchFactory.Create(this); this.m_cDispatch.OnConnect(); Receive(); } catch (Exception e) { WriteFiles.WritFile.Log(LogerType.ERROR, e.StackTrace); DisConnect(); ChangeStatus(SESSION_STATUS.CONNECT_FAILED_CONNECT_ERROR); } }
public DummySeverSession(DispatchFactoryBase dispatchFactory, int port) { this.m_cDispatchFactory = dispatchFactory; this.m_cDispatch = dispatchFactory.Create(this); this.m_iPort = port; }