Esempio n. 1
0
        public void Start()
        {
            _webSocketServer = new WebSocketServer();
            SuperSocket.SocketBase.Config.RootConfig rootConfig = new SuperSocket.SocketBase.Config.RootConfig();
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig();

            serverConfig.Name                = "PokeFeeder";
            serverConfig.ServerTypeName      = "WebSocketService";
            serverConfig.Ip                  = "Any";
            serverConfig.Port                = GlobalSettings.OutgoingServerPort;
            serverConfig.MaxRequestLength    = 4096;
            serverConfig.MaxConnectionNumber = 100 * 1000;
            serverConfig.SendingQueueSize    = 25;
            serverConfig.SendTimeOut         = 5000;
            var socketServerFactory = new SuperSocket.SocketEngine.SocketServerFactory();

            _webSocketServer.Setup(rootConfig, serverConfig, socketServerFactory);
            _webSocketServer.Start();
            _webSocketServer.NewMessageReceived  += new SessionHandler <WebSocketSession, string>(socketServer_NewMessageReceived);
            _webSocketServer.NewSessionConnected += socketServer_NewSessionConnected;
            _webSocketServer.SessionClosed       += socketServer_SessionClosed;

            UpdateTitle();
            var pokemonIds = GlobalSettings.UseFilter
? PokemonParser.ParsePokemons(new List <string>(GlobalSettings.PokekomsToFeedFilter))
: Enum.GetValues(typeof(PokemonId)).Cast <PokemonId>().ToList();

            _serverUploadFilter = ServerUploadFilterFactory.Create(pokemonIds);
        }
Esempio n. 2
0
        private void socketServer_NewSessionConnected(WebSocketSession session)
        {
            var uploadFilter = JsonConvert.SerializeObject(ServerUploadFilterFactory.Create(_pokemonIds));

            session.Send($"{GetEpoch()}:Hello Darkness my old friend.:{uploadFilter}");
            Log.Info($"[{_webSocketServer.SessionCount}:{session.SessionID}] Session started");
            UpdateTitle();
        }