Exemple #1
0
        /// <summary>
        /// Establish connection to the server.
        /// </summary>
        /// <returns>True if connected successfully.</returns>
        public bool Connect()
        {
            if (Running && reconnectAttempCount == 0)
            {
                return(false);
            }
            try
            {
                Logger.Log(this, "Connecting to: " + this.ip.ToString() + ":" + this.port.ToString());
                client.Connect(this.endPoint);
                stream = this.client.GetStream();
                if (communicationStream == null)
                {
                    communicationStream = new BitStringCommunicationStream(stream);
                }
                else
                {
                    communicationStream.InternalStream = stream;
                }

                if (keepAlive == null)
                {
                    keepAlive = new KeepAlive(communicationStream);
                    keepAlive.StartAync();
                }
                Logger.Log(this, "Connection established.");
                //send our agent id.
                if (NaoState.Instance.Connected)
                {
                    EventQueue.Goal.Post(new AgentEvent());
                    EventQueue.Goal.Post(new LocationEvent(initialPosition));
                    Logger.Say("Connected to Goal");
                }
                return(true);
            }
            catch (SocketException)
            {
                Logger.Log(this, "Connection could not be established, is the server running?");
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Establish connection to the server.
        /// </summary>
        /// <returns>True if connected successfully.</returns>
        public bool Connect()
        {
            if (Running && reconnectAttempCount == 0)
                return false;
            try
            {
                Logger.Log(this, "Connecting to: " + this.ip.ToString() + ":" + this.port.ToString());
                client.Connect(this.endPoint);
                stream = this.client.GetStream();
                if (communicationStream == null)
                    communicationStream = new BitStringCommunicationStream(stream);
                else communicationStream.InternalStream = stream;

                if (keepAlive == null) {
                    keepAlive = new KeepAlive(communicationStream);
                    keepAlive.StartAync();
                }
                Logger.Log(this, "Connection established.");
                //send our agent id.
                if (NaoState.Instance.Connected)
                {
                    EventQueue.Goal.Post(new AgentEvent());
                    EventQueue.Goal.Post(new LocationEvent(initialPosition));
                    Logger.Say("Connected to Goal");
                }
                return true;
            }
            catch (SocketException)
            {
                Logger.Log(this, "Connection could not be established, is the server running?");
                return false;
            }
        }