static void Main(string[] args) { LogConsole._Load(); LogDebug.debug = true; _SQL.Init("localhost", "root", "13456", "dbbase", 3306); var wssv = new WebSocketServiceHost<Serverb>("ws://192.168.1.5:8085"); wssv.OnError += (sender, e) => { Console.WriteLine("[WS] error", "WS: Error: " + e.Message, "notification-message-im"); }; wssv.Start(); Console.WriteLine("WebSocket Server listening on port: {0}", wssv.Port); while (true) { Thread.Sleep(1000); string _comm = Console.ReadLine(); switch (_comm) { case "count": Console.WriteLine("Users Online: {0}",Users.Count()); break; default: break; } } //Console.ReadKey(); }
internal bool TryGetServiceHostInternally(string path, out WebSocketServiceHost host) { path = HttpUtility.UrlDecode (path).TrimEndSlash (); bool result; lock (_sync) { result = _hosts.TryGetValue (path, out host); } if (!result) _logger.Error ("A WebSocket service with the specified path not found.\npath: " + path); return result; }
internal void Add(string path, WebSocketServiceHost host) { lock (_sync) { WebSocketServiceHost find; if (_hosts.TryGetValue (path, out find)) { _logger.Error ( "A WebSocket service with the specified path already exists.\npath: " + path); return; } if (_state == ServerState.Start) host.Sessions.Start (); _hosts.Add (path, host); } }
/// <summary> /// Tries to get the information in a WebSocket service with the specified /// <paramref name="path"/>. /// </summary> /// <returns> /// <c>true</c> if the WebSocket service is successfully found; otherwise, <c>false</c>. /// </returns> /// <param name="path"> /// A <see cref="string"/> that represents the absolute path to the WebSocket service to find. /// </param> /// <param name="host"> /// When this method returns, a <see cref="WebSocketServiceHost"/> instance that /// provides the access to the WebSocket service if it's successfully found; /// otherwise, <see langword="null"/>. This parameter is passed uninitialized. /// </param> public bool TryGetServiceHost(string path, out WebSocketServiceHost host) { var msg = _state.CheckIfStart () ?? path.CheckIfValidServicePath (); if (msg != null) { _logger.Error (msg); host = null; return false; } return TryGetServiceHostInternally (path, out host); }
static void Main(string[] args) { LogConsole._Load(); PATH = Environment.CurrentDirectory.ToString(); Inix ini = null; #region Load Settings try { if (File.Exists(PATH + @"\Settings\Settings.ini")) { ini = new Inix(PATH + @"\Settings\Settings.ini"); LSPort = ini.GetValue("Server", "port", 9002).ToString(); LSIP = ini.GetValue("Server", "ip", "localhost").ToString(); MIp = ini.GetValue("MySql", "ip", "localhost").ToString(); MUser = ini.GetValue("MySql", "user", "root").ToString(); MPass = ini.GetValue("MySql", "pass", "").ToString(); MDb = ini.GetValue("MySql", "db", "db_clone").ToString(); MPort = Convert.ToInt32(ini.GetValue("MySql", "port", 3306)); debug = Convert.ToBoolean(ini.GetValue("Console", "debug", false)); ini = null; LogConsole.Show(LogType.INFO, "Has loaded your ip settings successfully"); } else { LogConsole.Show(LogType.ALERT, "Settings.ini could not be found, using default setting"); } } catch (Exception excc) { LogConsole.Show(LogType.ERROR, " {0}", excc.ToString()); return; } #endregion _SQL.Init(MIp, MUser, MPass, MDb, MPort); MapsL.LoadMaps.Load(); WSurl = WSurl + LSIP + ":" + LSPort; var wssv = new WebSocketServiceHost<Serverb>(WSurl); wssv.OnError += (sender, e) => { LogConsole.Show(LogType.ERROR, "[WS]: Error {0} ", e.Message); }; wssv.Start(); LogConsole.Show(LogType.ALERT, "Server Listening on port: {0}", wssv.Port); _LoopThrreading = new Thread(new ThreadStart(Program.LoopConsole)); _LoopThrreading.Priority = ThreadPriority.BelowNormal; _LoopThrreading.Start(); while (true) { Thread.Sleep(1000); string _comm = Console.ReadLine(); switch (_comm) { case "online": LogConsole.Show(LogType.INFO, "Users Online: {0}", Users.Count()); break; default: break; } } }
internal void Add(string servicePath, WebSocketServiceHost serviceHost) { lock (_sync) { WebSocketServiceHost host; if (_serviceHosts.TryGetValue (servicePath, out host)) { _logger.Error ( "A WebSocket service with the specified path already exists.\npath: " + servicePath); return; } if (_state == ServerState.START) serviceHost.Sessions.Start (); _serviceHosts.Add (servicePath, serviceHost); } }