Пример #1
0
        static void Main(string[] args)
        {
            ListenerProxy     gameListener   = null;
            ListenerProxy     clientListener = null;
            HttpListenerProxy httpListener   = null;

            try
            {
                var gameTran   = new GameTransponder();
                var clientTran = new HttpTransponder();
                clientTran.ReceiveCompleted += gameTran.Send;
                clientTran.SocketClosing    += gameTran.OnTcpClientClosed;
                gameTran.ReceiveCompleted   += clientTran.Send;

                ConnectSetting gameSetting   = LoadGameSetting();
                ConnectSetting clientSetting = LoadClientSetting();
                HttpSettings   httpSetting   = LoadHttpSetting();
                gameListener   = new ListenerProxy(gameTran, gameSetting);
                clientListener = new ListenerProxy(clientTran, clientSetting);
                httpListener   = new HttpListenerProxy(httpSetting);
                httpListener.RequestCompleted += clientTran.Request;
                httpListener.RequestTimeout   += clientTran.RequestTimeout;
                clientTran.ResponseCompleted  += httpListener.PushSend;

                gameListener.Listen();
                Console.WriteLine("【游戏服监听端口:{0}】正在监听中...", gameSetting.Port);

                clientListener.Listen();
                Console.WriteLine("【客户端监听端口:{0}】正在监听中...", clientSetting.Port);

                httpListener.Listen();
                Console.WriteLine("【Http监听端口:{0}:{1}/{2}】正在监听中...", httpSetting.HostAddress, httpSetting.Port, httpSetting.GameAppName);

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("SocketServer error:{0}", ex);
            }
            finally
            {
                if (clientListener != null)
                {
                    clientListener.Dispose();
                }

                if (gameListener != null)
                {
                    gameListener.Dispose();
                }
                if (httpListener != null)
                {
                    httpListener.Dispose();
                }
            }
        }
Пример #2
0
 public int AddNotificationListener(object token, ObjectName name, NotificationFilterCallback filterCallback)
 {
     using (TemporarySecurityContext tsc = new TemporarySecurityContext(Authorize(token)))
     {
         int           listenerId = GetNextListenerId();
         ListenerProxy proxy      = new ListenerProxy(name, _buffer, listenerId, filterCallback);
         _listenerProxys.Add(listenerId, proxy);
         _server.AddNotificationListener(name, proxy.NotificationCallback, filterCallback, listenerId);
         return(listenerId);
     }
 }
Пример #3
0
 public int AddNotificationListener(object token, ObjectName name, NotificationFilterCallback filterCallback)
 {
     using (TemporarySecurityContext tsc = new TemporarySecurityContext(Authorize(token)))
     {
         int listenerId = GetNextListenerId();
         ListenerProxy proxy = new ListenerProxy(name, _buffer, listenerId, filterCallback);
         _listenerProxys.Add(listenerId, proxy);
         _server.AddNotificationListener(name, proxy.NotificationCallback, filterCallback, listenerId);
         return listenerId;
     }
 }
Пример #4
0
 public void RemoveNotificationListener(object token, ObjectName name, int listenerId)
 {
     using (TemporarySecurityContext tsc = new TemporarySecurityContext(Authorize(token)))
     {
         ListenerProxy proxy = _listenerProxys[listenerId];
         if (proxy.HasFilterCallback)
         {
             _server.RemoveNotificationListener(name, proxy.NotificationCallback, proxy.NotificationFilterCallback, listenerId);
         }
         else
         {
             _server.RemoveNotificationListener(name, proxy.NotificationCallback, null, listenerId);
         }
     }
 }
Пример #5
0
 bool IsWriteForListener(LogLevel level, ListenerProxy proxy)
 {
     return(level >= proxy.MinLevel && level <= proxy.MaxLevel);
 }