Esempio n. 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPing(ISocket sender, ConnectionEventArgs e)
 {
     sender.Pong(e.Socket);
 }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnHandshaked(ISocket sender, ConnectionEventArgs e)
        {

        }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPong(ISocket sender, ConnectionEventArgs e)
 {
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
0
 private void socketLintener_OnPing(ISocket sender, ConnectionEventArgs e)
 {
     try
     {
         OnPing(sender, e);
     }
     catch (Exception err)
     {
         TraceLog.WriteError("OnPing error:{0}", err);
     }
 }
Esempio n. 6
0
 protected override void OnHandshaked(ISocket sender, ConnectionEventArgs e)
 {
     Console.WriteLine("Client {0} connect to server.", e.Socket.RemoteEndPoint);
     base.OnHandshaked(sender, e);
 }
Esempio n. 7
0
 private void OnConnectCompleted(ISocket socket, ConnectionEventArgs e)
 {
     //Trace.WriteLine(string.Format("Server accept client {0} connected", e.Socket.RemoteEndPoint));
 }
Esempio n. 8
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;
     }
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appServer"></param>
 internal virtual void Bind(ISocket appServer)
 {
     AppServer = appServer;
 }
Esempio n. 10
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);
                }
            }
        }
Esempio n. 11
0
 private GameSession(Guid sid, ExSocket exSocket, ISocket appServer)
     : this(sid, null) {
     InitSocket(exSocket, appServer);
 }
Esempio n. 12
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);
 }
Esempio n. 13
0
 private void InitSocket(ExSocket exSocket, ISocket appServer)
 {
     _exSocket = exSocket;
     _remoteAddress = _exSocket.RemoteEndPoint.ToNotNullString();
     AppServer = appServer;
 }
Esempio n. 14
0
 private void OnPongEventHandler(ISocket sender, ConnectionEventArgs e) {
     try {
         OnPong(sender, e);
     } catch (Exception err) {
         TraceLog.WriteError("OnPong error:{0}", err);
     }
 }
Esempio n. 15
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");
 }
Esempio n. 16
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;
 }
Esempio n. 18
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);
     }
 }
Esempio n. 19
0
 protected override void OnError(ISocket sender, ConnectionEventArgs e)
 {
     Console.WriteLine("Server send to {0} data error.", e.Socket.RemoteEndPoint);
     base.OnError(sender, e);
 }
Esempio n. 20
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);
 }