public void AddSession(int sessionId, Session session) { lock (m_Sessions) { if (!m_Sessions.ContainsKey(sessionId)) m_Sessions.Add(sessionId, session); else m_Sessions[sessionId] = session; } }
public void OnError(Session session, Int32 errortype, String errormsg) { LogMsg("Client Error (" + session.GetId() + ") : " + errormsg); }
public void OnDisconnect(Session session) { LogMsg("Client Disconnected, ID: " + session.GetId()); Invoke((Action)(() => { if (m_UserName.Length > 0 && m_UserToken.Length > 0) { ShowText("ERROR: " + "Lost connection to chat server."); } gbLobby.Enabled = false; gbChatRoom.Enabled = false; gbLogin.Enabled = false; if (m_UserName.Length > 0 && m_UserToken.Length > 0) { ShowText("Trying to re-login, please wait..."); timerAutoRelogin.Enabled = true; timerAutoRelogin.Start(); } else gbLogin.Enabled = true; })); }
public void OnConnect(Session session) { LogMsg("Client Connected, ID: " + session.GetId()); if (m_UserName.Length > 0 && m_UserToken.Length > 0) { EnterLobbyRequest request = new EnterLobbyRequest(); request.UserName = m_UserName; request.UserToken = m_UserToken; m_Client.SendString("lobby/enter/" + WebMessage.ToJsonString<EnterLobbyRequest>(request)); } }
public void AcceptCallback(IAsyncResult ar) { // Signal the main thread to continue. Socket socket = null; lock (m_ListenWatcher) { try { // Get the socket that handles the client request. Socket listener = (Socket)ar.AsyncState; if (listener != null) socket = listener.EndAccept(ar); } catch { } } // after unlock the watcher, re-activate it ... m_ListenWatcher.Set(); if (socket == null) return; if (!m_Acceptable || m_State <= 0) { try { socket.Close(); } catch { } return; } if (m_MaxClientCount > 0 && m_SessionGroup.GetSessionCount() >= m_MaxClientCount) { try { socket.Close(); } catch { } return; } // set every new session's io buffer size to a global value by default // but you still can change it in every session's OnConnect event function socket.ReceiveBufferSize = m_IoBufferSize; socket.SendBufferSize = m_IoBufferSize; // Create the session object. Session session = null; lock (m_SessionGroup) { m_NextSessionID++; session = new Session(m_NextSessionID, socket, m_IoHandler, m_IoFilter, m_Cert != null); session.SetSessionGroup(m_SessionGroup); } if (session != null) { Stream stream = session.GetStream(); if (stream != null) { if (stream is SslStream && m_Cert != null) { (stream as SslStream).BeginAuthenticateAsServer(m_Cert, new AsyncCallback(AuthenticateCallback), session); } else if (stream is NetworkStream) { if (session != null) session.Open(); } } } }
public SessionContext(Session session, Object data) { Session = session; Data = data; }
public virtual void OnError(Session session, Int32 errortype, String errormsg) { try { if (m_Events != null) m_Events.FireErrorEvent(session, errortype, errormsg); } finally { if (session != null) session.Close(); } }
public virtual void OnDisconnect(Session session) { if (m_Events != null) m_Events.FireDisconnectEvent(session); }
public int FireSendEvent(Session session, Object data) { if (OnSend != null) return OnSend(session, data); else return 0; }
public int FireReceiveEvent(Session session, Object data) { if (OnReceive != null) return OnReceive(session, data); else return 0; }
public void FireIdleEvent(Session session, Int32 optype) { if (OnIdle != null) OnIdle(session, optype); }
public void FireErrorEvent(Session session, Int32 errortype, String errormsg) { if (OnError != null) OnError(session, errortype, errormsg); }
public void FireDisconnectEvent(Session session) { if (OnDisconnect != null) OnDisconnect(session); }
public virtual int OnSend(Session session, Object data) { if (m_Events != null) return m_Events.FireSendEvent(session, data); else return 0; }
public virtual int OnReceive(Session session, Object data) { if (m_Events != null) return m_Events.FireReceiveEvent(session, data); else return 0; }
public virtual void OnIdle(Session session, Int32 optype) { if (m_Events != null) m_Events.FireIdleEvent(session, optype); }