コード例 #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);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: blindsight/Talker
		public static void Main(string[] args)
		{
			// Check if the config file is correctly loaded
			if (System.Configuration.ConfigurationManager.AppSettings.Count == 0) {
				Console.WriteLine("ERROR: config file not loaded");
				return;
			}

			int AddressPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["port"]);
			int webSocketPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["webSocketPort"]);

			//TODO: error message port must be above 1024
			tcpListener = new TcpListener(IPAddress.Any, AddressPort);
			listenThread = new Thread(new ThreadStart(ListenForClients));
			listenThread.Start();
			System.Reflection.Assembly CurrentServer = System.Reflection.Assembly.GetExecutingAssembly();
			string ProductVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(CurrentServer.Location).ProductVersion;
			DateTime CurrentDateTime = DateTime.Now;

			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("{0} {1} server booting on {2} at {3}", CurrentServer.GetName().Name, ProductVersion, CurrentDateTime.ToLongDateString(), CurrentDateTime.ToLongTimeString());
			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("Node Name : {0}", System.Environment.MachineName);

		
			//Console.WriteLine("Running On : {0} {1}", (Is64) ? "x86_64": "x86" ,System.Environment.OSVersion.ToString());
			Console.WriteLine("Started server at " + AddressPort);

			SuperSocket.SocketBase.Config.RootConfig r = new SuperSocket.SocketBase.Config.RootConfig();

			SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();
			s.Name = "SuperWebSocket";
			s.Ip = "Any";
			s.Port = webSocketPort;
			s.Mode = SocketMode.Tcp;

			SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();


			if (ws != null)
			{
				ws.Stop();
				ws = null;
			}

			ws = new WebSocketServer();
			ws.Setup(r, s, f);
			ws.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(ws_SessionClosed);
			ws.NewSessionConnected += new SessionHandler<WebSocketSession>(ws_NewSessionConnected);
			ws.NewMessageReceived += new SessionHandler<WebSocketSession, string>(ws_NewMessageReceived);
			ws.NewDataReceived += new SessionHandler<WebSocketSession, byte[]>(ws_NewDataReceived);
			ws.Start();

			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("Booted with PID {0}", System.Diagnostics.Process.GetCurrentProcess().Id);
			Console.WriteLine("------------------------------------------------------------------------------");
		}
コード例 #3
0
ファイル: Main.cs プロジェクト: blindsight/Talker
        public static void Main(string[] args)
        {
            // Check if the config file is correctly loaded
            if (System.Configuration.ConfigurationManager.AppSettings.Count == 0) {
                Console.WriteLine("ERROR: config file not loaded");
                return;
            }

            int AddressPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["port"]);
            int webSocketPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["webSocketPort"]);

            //TODO: error message port must be above 1024
            tcpListener = new TcpListener(IPAddress.Any, AddressPort);
            listenThread = new Thread(new ThreadStart(ListenForClients));
            listenThread.Start();
            System.Reflection.Assembly CurrentServer = System.Reflection.Assembly.GetExecutingAssembly();
            string ProductVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(CurrentServer.Location).ProductVersion;
            DateTime CurrentDateTime = DateTime.Now;

            Console.WriteLine("------------------------------------------------------------------------------");
            Console.WriteLine("{0} {1} server booting on {2} at {3}", CurrentServer.GetName().Name, ProductVersion, CurrentDateTime.ToLongDateString(), CurrentDateTime.ToLongTimeString());
            Console.WriteLine("------------------------------------------------------------------------------");
            Console.WriteLine("Node Name : {0}", System.Environment.MachineName);

            //Console.WriteLine("Running On : {0} {1}", (Is64) ? "x86_64": "x86" ,System.Environment.OSVersion.ToString());
            Console.WriteLine("Started server at " + AddressPort);

            SuperSocket.SocketBase.Config.RootConfig r = new SuperSocket.SocketBase.Config.RootConfig();

            SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();
            s.Name = "SuperWebSocket";
            s.Ip = "Any";
            s.Port = webSocketPort;
            s.Mode = SocketMode.Tcp;

            SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();

            if (ws != null)
            {
                ws.Stop();
                ws = null;
            }

            ws = new WebSocketServer();
            ws.Setup(r, s, f);
            ws.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(ws_SessionClosed);
            ws.NewSessionConnected += new SessionHandler<WebSocketSession>(ws_NewSessionConnected);
            ws.NewMessageReceived += new SessionHandler<WebSocketSession, string>(ws_NewMessageReceived);
            ws.NewDataReceived += new SessionHandler<WebSocketSession, byte[]>(ws_NewDataReceived);
            ws.Start();

            Console.WriteLine("------------------------------------------------------------------------------");
            Console.WriteLine("Booted with PID {0}", System.Diagnostics.Process.GetCurrentProcess().Id);
            Console.WriteLine("------------------------------------------------------------------------------");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: kenlimmj/quetzalcoatl
        static void socketServer_Initialize()
        {
            // Initialize the server object
            SuperWebSocket.WebSocketServer socketServer = new WebSocketServer ();

            // Initialize basic server configurations
            SuperSocket.SocketBase.Config.RootConfig socketRootConfig = new SuperSocket.SocketBase.Config.RootConfig ();
            SuperSocket.SocketBase.Config.ServerConfig socketServerConfig = new SuperSocket.SocketBase.Config.ServerConfig ();
            SuperSocket.SocketEngine.SocketServerFactory socketServerFactory = new SuperSocket.SocketEngine.SocketServerFactory ();

            // Set the name, IP address and port number which the server is started on
            socketServerConfig.Name = "Quetzalcoatl Server";
            socketServerConfig.Ip = "127.0.0.1";
            socketServerConfig.Port = 1620;

            // Print boilerplate text when the console is first displayed
            logConsoleBoilerplate ();

            // Create the server using the specifications created above
            // If the server fails to start, write to the console
            if (!socketServer.Setup (socketRootConfig, socketServerConfig, socketServerFactory)) {
                Console.WriteLine ("Failed to initialize server at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port);
                Console.ReadKey ();
                return;
            }

            // Start the server
            // If the server fails to start, write to the console
            if (!socketServer.Start ()) {
                Console.WriteLine ("Server was successfully initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port +
                " but failed to start. Ensure that no processes are currently running at the same address.");
                Console.ReadKey ();
                return;
            }

            // Notify the user that the server has successfully started and is awaiting connections
            Console.WriteLine ("Server initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port + " at " + socketServer.StartedTime);
            Console.WriteLine ("Awaiting client connections...");
            Console.WriteLine ();

            // Bind listeners for server events
            socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string> (socketServer_NewMessageReceived);
            socketServer.NewSessionConnected += socketServer_NewSessionConnected;
            socketServer.SessionClosed += socketServer_SessionClosed;

            // Nullify all console inputs except for when the user types "exit"
            while (Console.ReadLine () != "exit") {
                continue;
            }

            // Properly shutdown the server by waiting on the buffer and freeing all used ports
            socketServer_Shutdown (socketServer);

            return;
        }
コード例 #5
0
        private void CreateServerWebSocket()
        {
            var rootConfig   = new SuperSocket.SocketBase.Config.RootConfig();
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig
            {
                Name = Constants.ServerWebSocketString,
                Ip   = "Any",
                Port = this.WebSocketPort,
                Mode = SocketMode.Tcp
            };

            this.webSocketServer = new WebSocketServer();
            this.webSocketServer.Setup(rootConfig, serverConfig, new SuperSocket.SocketEngine.SocketServerFactory());
            this.webSocketServer.NewSessionConnected += new SessionHandler <WebSocketSession>(ServerWebSocket_NewSessionConnected);
            this.webSocketServer.NewMessageReceived  += new SessionHandler <WebSocketSession, string>(ServerWebSocket_NewMessageReceived);
            this.webSocketServer.NewDataReceived     += new SessionHandler <WebSocketSession, byte[]>(ServerWebSocket_NewDataReceived);
        }
コード例 #6
0
        private EmbeddedWebServer(HttpRequestHandler handler)
        {
            if (!HttpListener.IsSupported)
            {
                Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
                throw new NotSupportedException("SimpleListenerExample");
            }

            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this._httpHandler = handler;

            // Setup the web sockets
            _socketServer = new WebSocketServer();
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig
            {
                Name = "SuperWebSockets",
                Ip   = "Any",
                Port = handler.WebSocketPort,
                Mode = SocketMode.Tcp
            };
            var rootConfig = new SuperSocket.SocketBase.Config.RootConfig();
            var factory    = new SuperSocket.SocketEngine.SocketServerFactory();

            _socketServer.NewSessionConnected += _socketServer_NewSessionConnected;
            _socketServer.SessionClosed       += _socketServer_SessionClosed;
            _socketServer.NewMessageReceived  += _socketServer_NewMessageReceived;
            _socketServer.NewDataReceived     += _socketServer_NewDataReceived;
            _socketServer.Setup(rootConfig, serverConfig, factory);
            _socketServer.Start();

            // Setup the web server
            _httpListener = new HttpListener();
            _httpListener.Prefixes.Add(handler.WebPrefix);
            _httpListener.Start();
            StartListening();

            string chromeArgs = " --app=" + handler.WebPrefix;

            System.Diagnostics.Process.Start(handler.PathOfChromeExecutable, chromeArgs);
        }
コード例 #7
0
        private void setup_server(ref WebSocketServer server, SuperSocket.SocketBase.Config.ServerConfig serverConfig)
        {
            var rootConfig = new SuperSocket.SocketBase.Config.RootConfig();

            server = new SuperSocket.WebSocket.WebSocketServer();

            //サーバーオブジェクト作成&初期化
            server.Setup(rootConfig, serverConfig);

            //イベントハンドラの設定
            //接続
            server.NewSessionConnected += HandleServerNewSessionConnected;
            //メッセージ受信
            server.NewMessageReceived += HandleServerNewMessageReceived;
            //切断
            server.SessionClosed += HandleServerSessionClosed;

            //サーバー起動
            server.Start();
        }
コード例 #8
0
        /**
         * @Method constructor that initializates the Secure WebSocket on default port 1443
         */
        public SecureSuperSocketController()
        {
            this.Log = LogManager.GetLogger(Properties.Settings.Default.logName);
            int port = 1443;
            SuperSocket.SocketBase.Config.RootConfig r = new SuperSocket.SocketBase.Config.RootConfig();

            SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();

            //Using 80 or 9999 port is working

            s.Name = "SuperWebSocket";
            s.Ip = "127.0.0.1";
            s.Port = port;
            s.Mode = SocketMode.Tcp;
            s.Security = "tls";

            SuperSocket.SocketBase.Config.CertificateConfig cert = new SuperSocket.SocketBase.Config.CertificateConfig();

            string pathToBaseDir = System.IO.Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            cert.FilePath = System.IO.Path.Combine(pathToBaseDir, "galeonssl.pfx");
            System.Diagnostics.Debug.Assert(System.IO.File.Exists(cert.FilePath));
            cert.Password = "******";

            s.Certificate = cert;

            SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();

            base.appServer = new WebSocketServer();
            try
            {
                base.appServer.Setup(r, s, f);
                Log.Debug("Secure WebSocket Started at port " + port);
                base.appServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(this.appServer_NewMessageReceived);
            }
            catch (Exception ex)
            {
                Log.Error("Error while creating Socket on port " + port, ex);
                this.appServer = null;
            }
        }
コード例 #9
0
ファイル: WebSocket.cs プロジェクト: gayanj/SEP_PROJECT_ACRM
        /// <summary>
        /// Create a Unique Session.
        /// </summary>
        /// <param name="ErrorMessage">Error Information for failiures.</param>
        /// <returns>Returns True if session creation was successful.</returns>
        public bool CreateUniqueSession()
        {
            try
            {
                Console.WriteLine("Starting Socket Server.");
                FileLogger.Instance.LogMessage("Starting Socket Server.");
                SuperSocket.SocketBase.Config.RootConfig r = new SuperSocket.SocketBase.Config.RootConfig();

                SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();
                string rootFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                s.Name = "SecureSuperWebSocket";
                s.Ip   = "127.0.0.1";
                s.Port = _port;
                s.Mode = SocketMode.Tcp;

                //s.Security = "tls";
                //s.Certificate = new SuperSocket.SocketBase.Config.CertificateConfig
                //{
                //    FilePath = @"localhost_sticky_ad.pfx",
                //    Password = "******"
                //};
                appServer = new WebSocketServer();
                appServer.Setup(r, s);
                appServer.NewSessionConnected += new SessionHandler <WebSocketSession>(AppServerNewSessionConnected);
                appServer.NewMessageReceived  += new SessionHandler <WebSocketSession, string>(AppServerNewMessageReceived);
                appServer.SessionClosed       += new SessionHandler <WebSocketSession, CloseReason>(AppServerSessionClosed);
                appServer.Start();
                Console.WriteLine("Socket Server Started. IP=" + s.Ip + ". Port=" + s.Port);
                FileLogger.Instance.LogMessage("Socket Server Started. IP=" + s.Ip + ". Port=" + s.Port);
                return(true);
            }
            catch (Exception exception)
            {
                FileLogger.Instance.LogException(exception);
                return(false);
            }
        }
コード例 #10
0
        private void InitWebsocketServer()
        {
            Console.WriteLine("WebSocketServer is starting!");
            appServer = new GameWebsocketServer();

            SuperSocket.SocketBase.Config.RootConfig   r = new SuperSocket.SocketBase.Config.RootConfig();
            SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();
            s.Name             = "SuperWebSocket";
            s.ServerTypeName   = "WebSocketService";
            s.Ip               = "Any";
            s.Port             = 2012;
            s.MaxRequestLength = 1024 * 1000 * 1000;
            SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();

            appServer.Setup(r, s, f);

            appServer.NewMessageReceived +=
                new SuperSocket.SocketBase.SessionHandler <GameWebsocketSession, string>(
                    appServer_NewMessageReceived);
            appServer.NewSessionConnected +=
                new SuperSocket.SocketBase.SessionHandler <GameWebsocketSession>(
                    appServer_NewSessionConnected
                    );


            Console.WriteLine();

            //Try to start the appServer
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully!");
        }
コード例 #11
0
        public bool SuperSocketSetup(Server server)
        {
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig
            {
                Name                    = "DrivingSuperSocket",                  //The name of the server instance
                ServerType              = "DrivingTest.Socket.BinaryServer, Drivingtest.Socket",
                Ip                      = "Any",                                 //Any - all IPv4 addresses IPv6Any - all IPv6 addresses
                Mode                    = SuperSocket.SocketBase.SocketMode.Tcp, //The mode the server is running, Tcp (default) or Udp
                Port                    = Convert.ToInt32(txtPort.Text.Trim()),  //Server listening port
                SendingQueueSize        = 10,                                    //The maximum length of the send queue. The default value is 5.
                MaxConnectionNumber     = 10000,                                 //Maximum number of connections that can be allowed to connect
                LogCommand              = false,                                 //Whether to record the record of command execution
                LogBasicSessionActivity = false,                                 // Whether to record the basic activities of the session, such as connecting and disconnecting
                LogAllSocketException   = false,                                 //Whether to record all Socket exceptions and errors
                MaxRequestLength        = 1024 * 10,                             //Maximum allowed request length, default is 1024
                KeepAliveTime           = 600,                                   //The interval for sending keep alive data under normal network connection. The default value is 600, in seconds.
                KeepAliveInterval       = 60,                                    //After the keep alive fails, keep alive probe packet sending interval, the default value is 60, the unit is second
                //IdleSessionTimeOut = 60,
                //SendTimeOut = 1,
                ClearIdleSession         = false, // Whether to empty the idle session periodically, the default value is false;
                ClearIdleSessionInterval = 6      //: The interval for clearing idle sessions. The default value is 120, in seconds.
            };

            var rootConfig = new SuperSocket.SocketBase.Config.RootConfig()
            {
                MaxWorkingThreads               = 1000,                    //The maximum number of worker threads in the thread pool
                MinWorkingThreads               = 10,                      // The minimum number of worker threads in the thread pool;
                MaxCompletionPortThreads        = 1000,                    // thread pool maximum completion port thread number;
                MinCompletionPortThreads        = 10,                      // The thread pool minimum completion port thread number;
                DisablePerformanceDataCollector = true,                    // Whether to disable performance data collection;
                PerformanceDataCollectInterval  = 60,                      // Performance data acquisition frequency (in seconds, default: 60);
                Isolation = SuperSocket.SocketBase.IsolationMode.AppDomain // Server instance isolation level
            };

            return(server.Setup(rootConfig, serverConfig));
        }
コード例 #12
0
        private void CreateServerWebSocket()
        {
            var rootConfig = new SuperSocket.SocketBase.Config.RootConfig();
            var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig
            {
                Name = Constants.ServerWebSocketString,
                Ip = "Any",
                Port = this.WebSocketPort,
                Mode = SocketMode.Tcp
            };

            this.webSocketServer = new WebSocketServer();
            this.webSocketServer.Setup(rootConfig, serverConfig, new SuperSocket.SocketEngine.SocketServerFactory());
            this.webSocketServer.NewSessionConnected += new SessionHandler<WebSocketSession>(ServerWebSocket_NewSessionConnected);
            this.webSocketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(ServerWebSocket_NewMessageReceived);
            this.webSocketServer.NewDataReceived += new SessionHandler<WebSocketSession, byte[]>(ServerWebSocket_NewDataReceived);
        }