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); }
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("------------------------------------------------------------------------------"); }
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("------------------------------------------------------------------------------"); }
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); }
/** * @Method constructor that initializates the Secure WebSocket on port send by parameter * @Parameter port where WebSocket will listen */ public SecureSuperSocketController(int port) { this.Log = LogManager.GetLogger(Properties.Settings.Default.logName); 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; } }
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!"); }