Exemple #1
0
        public TunnelSettings LoadFromXML(String filepath)
        {
            XmlSerializer  deserializer  = new XmlSerializer(typeof(TunnelSettings));
            TextReader     textReader    = new StreamReader(filepath);
            Object         obj           = deserializer.Deserialize(textReader);
            TunnelSettings myNewSettings = (TunnelSettings)obj;

            textReader.Close();
            return(myNewSettings);
        }
Exemple #2
0
        public bool Start(TunnelSettings settings)
        {
            Connection <MonoBrick.NXT.Command, MonoBrick.NXT.Reply> connection = null;

            switch (settings.Connection.ToLower())
            {
            case  "usb":
                connection = new USB <MonoBrick.NXT.Command, MonoBrick.NXT.Reply>();
                break;

            case "loopback":
                connection = new Loopback <MonoBrick.NXT.Command, MonoBrick.NXT.Reply>();
                break;

            default:
                connection = new Bluetooth <MonoBrick.NXT.Command, MonoBrick.NXT.Reply>(settings.Connection);
                break;
            }
            return(Start(settings, connection));
        }
Exemple #3
0
        public bool Start(TunnelSettings settings, Connection <MonoBrick.NXT.Command, MonoBrick.NXT.Reply> connection)
        {
            if (settings.LogFileName != "")
            {
                try{
                    logFile.Open(settings.LogFileName);
                }
                catch
                {
                    logQueue.AddToQueue("Failed to open log file " + settings.LogFileName);
                }
            }
            this.settings = settings;
            Brick         = connection;
            string      sHostName = Dns.GetHostName();
            IPHostEntry ipE       = Dns.GetHostByName(sHostName);

            IPAddress []  ipv4Addresses = ipE.AddressList;
            List <string> list          = new List <string>();

            for (int i = 0; i < ipv4Addresses.Length; i++)
            {
                if (ipv4Addresses[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    list.Add(ipv4Addresses[i].ToString());
                }
            }
            ListeningAddress = list.ToArray();
            //IPAddress = ipv4Addresses[0].ToString();
            ListeningPort             = settings.Port;
            tcpListener               = new TcpListener(System.Net.IPAddress.Any, settings.Port);
            listenThread              = new Thread(new ThreadStart(ListenForClients));
            listenThread.IsBackground = true;
            IsRunning         = false;
            this.addressRange = settings.IPRangeToArray();

            /*Unsibscribed in "on tunnel stopped"*/
            Brick.Disconnected += OnBrickDisconnected;
            Brick.Connected    += OnBrickConnected;

            logQueue.AddToQueue("Connecting to Brick using " + settings.Connection);
            try{
                Brick.Open();
            }
            catch {
                logQueue.AddToQueue("Tunnel not started. Failed to connect to Brick");
                return(false);
            }
            logQueue.AddToQueue("Maximum number of connections " + settings.MaxConnections);
            if (settings.ListenForClients)
            {
                listenThread.Start();
            }
            else
            {
                logQueue.AddToQueue("Tunnel is not listening for clients");
            }
            IsRunning = true;
            if (Started != null)
            {
                Started();
            }
            return(true);
        }