Example #1
0
        private void openConnection()
        {
            if (this.isInit)
            {
                return;
            }

            try
            {
                this.rconReader = RCONReader.INSTANCE;
                this.tcp        = new TcpClient(this.server, this.port);
                this.stream     = this.tcp.GetStream();
                this.writer     = new BinaryWriter(this.stream);
                this.reader     = new BinaryReader(this.stream);
                this.rconReader.setup(this.reader);

                if (this.password != string.Empty)
                {
                    var answer = this.internalSendAuth();
                    if (answer == RCONMessageAnswer.EMPTY)
                    {
                        this.isInit = false;
                        return;
                    }
                }

                this.isInit = true;
            }
            catch (Exception e)
            {
                //Console.WriteLine("Exception while connecting: " + e.Message);
                ErrorMsg = "Exception while connecting: " + e.Message;

                this.isInit = false;
            }
            finally
            {
                // To prevent huge CPU load if many reconnects happens.
                // Does not effect any normal case ;-)
                Thread.Sleep(TimeSpan.FromSeconds(0.1));
            }
        }
		private void openConnection()
		{
			if (this.isInit)
			{
				return;
			}

			try
			{
				this.rconReader = RCONReader.INSTANCE;
				this.tcp = new TcpClient(this.server, this.port);
				this.stream = this.tcp.GetStream();
				this.writer = new BinaryWriter(this.stream);
				this.reader = new BinaryReader(this.stream);
				this.rconReader.setup(this.reader);

				if (this.password != string.Empty)
				{
					var answer = this.internalSendAuth();
					if (answer == RCONMessageAnswer.EMPTY)
					{
						this.isInit = false;
						throw new Exception("IPAddress or Password error!");
					}
				}

				this.isInit = true;
			}
			catch (Exception e)
			{
				this.isInit = false;
				this.isConfigured = false;
				throw e;
			}
			finally
			{
				// To prevent huge CPU load if many reconnects happens.
				// Does not effect any normal case ;-)
				Thread.Sleep(TimeSpan.FromSeconds(0.1));
			}
		}