Beispiel #1
0
        /// <summary>
        /// Процедура запуска сервера
        /// </summary>
        /// <returns></returns>
        private bool Start()
        {
            try
            {
                _host = new SBServerHost(25125, this.ServerName, this.ServerDiscoverable);
                _host.OnNewConnection += (clnt, cnn) => this.Invoke(() => {
                    this.Append(clnt.Id, clnt.Name, "[Новое соединение]");

                    cnn.OnConnectionLost += () => this.Invoke(() => {
                        this.Append(clnt.Id, clnt.Name, "[Соединение потеряно]");
                    });
                });

                this.Host = new ServerHostModel(_host);
                _host.Start();

                this.Append(Guid.Empty, string.Empty, "[Сервер запущен под именем \"" + _host.Name + "\"]");
                return(true);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                this.Stop();
                this.Append(Guid.Empty, string.Empty, ex.ToString());
                return(false);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Процедура остановки сервера
 /// </summary>
 /// <returns></returns>
 private bool Stop()
 {
     if (_host != null)
     {
         _host.Dispose();
         _host = null;
         this.Append(Guid.Empty, string.Empty, "[Сервер остановлен]");
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
 public ServerHostModel(SBServerHost host)
 {
     _host = host;
 }