Internal URL parsing engine
        /* Methods */
        /// <summary>
        /// UDP multicast provider constructor
        /// </summary>
        /// <param name="lcm">LCM object</param>
        /// <param name="up">URL parser object</param>
        public UDPMulticastProvider(LCM lcm, URLParser up)
        {
            this.lcm = lcm;

            string[] addrport = up.Get("network", DEFAULT_NETWORK).Split(':');

            inetAddr = Dns.GetHostAddresses(addrport[0])[0];
            inetPort = Int32.Parse(addrport[1]);
            inetEP   = new IPEndPoint(inetAddr, inetPort);
            Debug.Log(inetEP);

            sock = new UdpClient();
            sock.MulticastLoopback   = true;
            sock.ExclusiveAddressUse = false;
            sock.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            sock.Client.Bind(new IPEndPoint(IPAddress.Any, inetPort));

            int ttl = up.Get("ttl", DEFAULT_TTL);

            if (ttl == 0)
            {
                Console.Error.WriteLine("LCM: TTL set to zero, traffic will not leave localhost.");
            }
            else if (ttl > 1)
            {
                Console.Error.WriteLine("LCM: TTL set to > 1... That's almost never correct!");
            }
            else
            {
                Console.Error.WriteLine("LCM: TTL set to 1.");
            }
            sock.Ttl = (short)ttl;

            sock.JoinMulticastGroup(inetAddr);
        }
예제 #2
0
파일: TCPProvider.cs 프로젝트: obiben/lcm
        /* Methods */
        /// <summary>
        /// TCP provider constructor
        /// </summary>
        /// <param name="lcm">LCM object</param>
        /// <param name="up">URL parser object</param>
        public TCPProvider(LCM lcm, URLParser up)
        {
            this.lcm = lcm;

            string[] addrport = up.Get("network", DEFAULT_NETWORK).Split(':');
            if (addrport.Length == 1)
            {
                inetAddr = System.Net.Dns.GetHostAddresses(addrport[0])[0];
                inetPort = 7700;
            }
            else if (addrport.Length == 2)
            {
                inetAddr = System.Net.Dns.GetHostAddresses(addrport[0])[0];
                inetPort = Int32.Parse(addrport[1]);
            }
            else
            {
                Console.Error.WriteLine("TCPProvider: Don't know how to parse " + up.Get("network", DEFAULT_NETWORK));
                Environment.Exit(-1);
            }

            reader = new ReaderThread(this);

            reader.Connected    += OnConnect;
            reader.Disconnected += OnDisconnect;

            reader.Start();
        }
예제 #3
0
        /* Methods */
        /// <summary>
        /// UDP multicast provider constructor
        /// </summary>
        /// <param name="lcm">LCM object</param>
        /// <param name="up">URL parser object</param>
		public UDPMulticastProvider(LCM lcm, URLParser up)
		{
			this.lcm = lcm;
			
			string[] addrport = up.Get("network", DEFAULT_NETWORK).Split(':');
			
			inetAddr = Dns.GetHostAddresses(addrport[0])[0];
			inetPort = Int32.Parse(addrport[1]);
            inetEP = new IPEndPoint(inetAddr, inetPort);

            sock = new UdpClient();
            sock.MulticastLoopback = true;
            sock.ExclusiveAddressUse = false;
            sock.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            sock.Client.Bind(new IPEndPoint(IPAddress.Any, inetPort));
			
			int ttl = up.Get("ttl", DEFAULT_TTL);
            if (ttl == 0)
            {
                Console.Error.WriteLine("LCM: TTL set to zero, traffic will not leave localhost.");
            }
            else if (ttl > 1)
            {
                Console.Error.WriteLine("LCM: TTL set to > 1... That's almost never correct!");
            }
            else
            {
                Console.Error.WriteLine("LCM: TTL set to 1.");
            }
            sock.Ttl = (short) ttl;
			
			sock.JoinMulticastGroup(inetAddr);
		}
예제 #4
0
파일: LCM.cs 프로젝트: obiben/lcm
        /// <summary>
        /// Create a new LCM object, connecting to one or more URLs. If
        /// no URL is specified, the environment variable LCM_DEFAULT_URL is
        /// used. If that environment variable is not defined, then the
        /// default URL is used.
        /// </summary>
        /// <param name="urls">URL array</param>
        public LCM(params string[] urls)
        {
            if (urls.Length == 0)
            {
                string env = Environment.GetEnvironmentVariable("LCM_DEFAULT_URL");

                if (env == null)
                {
                    urls = new string[] { "udpm://239.255.76.67:7667" };
                }
                else
                {
                    urls = new string[] { env };
                }
            }

            foreach (string url in urls)
            {
                URLParser up       = new URLParser(url);
                string    protocol = up.Get("protocol");

                if (protocol.Equals("udpm"))
                {
                    providers.Add(new UDPMulticastProvider(this, up));
                }
                else if (protocol.Equals("tcpq"))
                {
                    TCPProvider prov = new TCPProvider(this, up);
                    prov.Connected    += OnTCPConnected;
                    prov.Disconnected += OnTCPDisconnected;
                    providers.Add(prov);
                }/*
                  * else if (protocol.Equals("file"))
                  * {
                  * providers.Add(new LogFileProvider(this, up));
                  * }*/
                else
                {
                    Console.Error.WriteLine("LCM: Unknown URL protocol: " + protocol);
                }
            }
        }
예제 #5
0
		/* Methods */
		/// <summary>
		/// TCP provider constructor
		/// </summary>
		/// <param name="lcm">LCM object</param>
		/// <param name="up">URL parser object</param>
		public TCPProvider(LCM lcm, URLParser up)
		{
			this.lcm = lcm;
			
			string[] addrport = up.Get("network", DEFAULT_NETWORK).Split(':');
			if (addrport.Length == 1)
			{
				inetAddr = System.Net.Dns.GetHostAddresses(addrport[0])[0];
				inetPort = 7700;
			}
			else if (addrport.Length == 2)
			{
				inetAddr = System.Net.Dns.GetHostAddresses(addrport[0])[0];
				inetPort = Int32.Parse(addrport[1]);
			}
			else
			{
				Console.Error.WriteLine("TCPProvider: Don't know how to parse " + up.Get("network", DEFAULT_NETWORK));
				Environment.Exit(-1);
			}
			
			reader = new ReaderThread(this);
			reader.Start();
		}
예제 #6
0
		/// <summary>
		/// Create a new LCM object, connecting to one or more URLs. If
		/// no URL is specified, the environment variable LCM_DEFAULT_URL is
		/// used. If that environment variable is not defined, then the
		/// default URL is used.
		/// </summary>
		/// <param name="urls">URL array</param>
		public LCM(params string[] urls)
		{
			if (urls.Length == 0)
			{
				string env = Environment.GetEnvironmentVariable("LCM_DEFAULT_URL");
				
				if (env == null)
				{
					urls = new string[] { "udpm://239.255.76.67:7667" };
				}
				else
				{
					urls = new string[] { env };
				}
			}
			
			foreach (string url in urls)
			{
				URLParser up = new URLParser(url);
				string protocol = up.Get("protocol");
				
				if (protocol.Equals("udpm"))
				{
					providers.Add(new UDPMulticastProvider(this, up));
				}
				else if (protocol.Equals("tcpq"))
				{
					providers.Add(new TCPProvider(this, up));
				}/*
                else if (protocol.Equals("file"))
                {
                    providers.Add(new LogFileProvider(this, up));
                }*/
				else
				{
					Console.Error.WriteLine("LCM: Unknown URL protocol: " + protocol);
				}
			}
		}