Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPong(ISocket sender, ConnectionEventArgs e)
 {
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPing(ISocket sender, ConnectionEventArgs e)
 {
     sender.Pong(e.Socket);
 }
Ejemplo n.º 3
0
 private void socketLintener_OnPing(ISocket sender, ConnectionEventArgs e)
 {
     try
     {
         OnPing(sender, e);
     }
     catch (Exception err)
     {
         TraceLog.WriteError("OnPing error:{0}", err);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnHandshaked(ISocket sender, ConnectionEventArgs e)
        {

        }
Ejemplo n.º 5
0
 private void OnConnectCompleted(ISocket socket, ConnectionEventArgs e)
 {
     //Trace.WriteLine(string.Format("Server accept client {0} connected", e.Socket.RemoteEndPoint));
 }
Ejemplo n.º 6
0
 private void OnDisconnected(ISocket sender, ConnectionEventArgs e)
 {
     try
     {
         GameSession session = GameSession.Get(e.Socket.HashCode);
         if (session != null)
         {
             OnDisconnected(session);
             session.ProxySid = Guid.Empty;
             session.Close();
         }
     }
     catch (Exception err)
     {
         TraceLog.WriteError("Disconnected error:{0}", err);
     }
 }
Ejemplo n.º 7
0
 internal void InitSocket(ExSocket exSocket, ISocket appServer) {
     _exSocket = exSocket;
     if (_exSocket != null) _remoteAddress = _exSocket.RemoteEndPoint.ToNotNullString();
     AppServer = appServer;
     if (User != null) {
         //update userid with sid.
         _userHash[UserId] = KeyCode;
     }
 }
Ejemplo n.º 8
0
 protected override void OnHandshaked(ISocket sender, ConnectionEventArgs e)
 {
     Console.WriteLine("Client {0} connect to server.", e.Socket.RemoteEndPoint);
     base.OnHandshaked(sender, e);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Recover session
        /// </summary>
        /// <param name="session"></param>
        /// <param name="newSessionKey"></param>
        /// <param name="socket"></param>
        /// <param name="appServer"></param>
        /// <returns></returns>
        public static void Recover(GameSession session, Guid newSessionKey, ExSocket socket, ISocket appServer) {
            var newSession = Get(newSessionKey);
            if (session != null &&
                newSession != null &&
                session != newSession) {

                try {
                    if (session._exSocket != null) session._exSocket.Close();
                } catch { }
                //modify socket's keycod not found reason
                if (socket != null && appServer != null) {
                    socket.Reset(session.KeyCode);
                    session._exSocket = socket;
                    session.AppServer = appServer;
                }
                GameSession temp;
                if (_globalSession.TryRemove(newSessionKey, out temp)) {
                    Save(session);
                }
            }
        }
Ejemplo n.º 10
0
 private GameSession(Guid sid, ExSocket exSocket, ISocket appServer)
     : this(sid, null) {
     InitSocket(exSocket, appServer);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Add session to cache
 /// </summary>
 /// <param name="keyCode"></param>
 /// <param name="socket"></param>
 /// <param name="appServer"></param>
 public static GameSession CreateNew(Guid keyCode, ExSocket socket, ISocket appServer) {
     return OnCreate(keyCode, socket, appServer);
 }
Ejemplo n.º 12
0
 private void InitSocket(ExSocket exSocket, ISocket appServer)
 {
     _exSocket = exSocket;
     _remoteAddress = _exSocket.RemoteEndPoint.ToNotNullString();
     AppServer = appServer;
 }
Ejemplo n.º 13
0
 private void OnPongEventHandler(ISocket sender, ConnectionEventArgs e) {
     try {
         OnPong(sender, e);
     } catch (Exception err) {
         TraceLog.WriteError("OnPong error:{0}", err);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnError(ISocket sender, ConnectionEventArgs e)
 {
     sender.CloseHandshake(e.Socket, "param error");
 }
Ejemplo n.º 15
0
 private void socketLintener_OnConnectCompleted(ISocket sender, ConnectionEventArgs e)
 {
     try
     {
         var session = GameSession.CreateNew(e.Socket.HashCode, e.Socket, socketListener);
         session.HeartbeatTimeoutHandle += OnHeartbeatTimeout;
         OnConnectCompleted(sender, e);
     }
     catch (Exception err)
     {
         TraceLog.WriteError("ConnectCompleted error:{0}", err);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="appServer"></param>
 internal virtual void Bind(ISocket appServer)
 {
     AppServer = appServer;
 }
Ejemplo n.º 17
0
 private void OnDataReceived(ISocket sender, ConnectionEventArgs e)
 {
     try
     {
         RequestPackage package;
         if (!ActionDispatcher.TryDecodePackage(e, out package))
         {
             //check command
             string command = e.Meaage.Message;
             if ("ping".Equals(command, StringComparison.OrdinalIgnoreCase))
             {
                 OnPing(sender, e);
                 return;
             }
             if ("pong".Equals(command, StringComparison.OrdinalIgnoreCase))
             {
                 OnPong(sender, e);
                 return;
             }
             OnError(sender, e);
             return;
         }
         var session = GetSession(e, package);
         if (CheckSpecialPackge(package, session))
         {
             return;
         }
         package.Bind(session);
         ProcessPackage(package, session).Wait();
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Received to Host:{0} error:{1}", e.Socket.RemoteEndPoint, ex);
     }
 }
Ejemplo n.º 18
0
 protected override void OnError(ISocket sender, ConnectionEventArgs e)
 {
     Console.WriteLine("Server send to {0} data error.", e.Socket.RemoteEndPoint);
     base.OnError(sender, e);
 }
Ejemplo n.º 19
0
 private void OnReceivedCompleted(ISocket socket, ConnectionEventArgs e)
 {
     Trace.WriteLine(string.Format("Received client {0} data {1}", e.Socket.RemoteEndPoint, Encoding.UTF8.GetString(e.Data)));
     socket.PostSend(e.Socket, e.Data, 0, e.Data.Length);
 }