Exemple #1
0
 public void Listen(string ip, int port)
 {
     Logger.Log(this, "Listening...");
     listener = new TcpListener(IPAddress.Parse(ip), port);
     listener.Start();
     try
     {
         client = listener.AcceptTcpClient();
         Logger.Log(this, "Accepted a client.");
         goalStream = new BitStringCommunicationStream(client.GetStream());
         listener.Stop();
         Logger.Log(this, "Stopped listening.");
     }
     catch (SocketException)
     {
         Logger.Log(this, "Interrupted while listening.");
     }
 }
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);
            }
        }
Exemple #3
0
 public KeepAlive(ICommunicationStream stream)
 {
     this.stream = stream;
 }
Exemple #4
0
 public KeepAlive(ICommunicationStream stream)
 {
     this.stream = stream;
 }
Exemple #5
0
 public void Listen(string ip, int port)
 {
     Logger.Log(this, "Listening...");
     listener = new TcpListener(IPAddress.Parse(ip), port);
     listener.Start();
     try
     {
         client = listener.AcceptTcpClient();
         Logger.Log(this, "Accepted a client.");
         goalStream = new BitStringCommunicationStream(client.GetStream());
         listener.Stop();
         Logger.Log(this, "Stopped listening.");
     }
     catch (SocketException)
     {
         Logger.Log(this, "Interrupted while listening.");
     }
 }
Exemple #6
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;
            }
        }