TTL值 - TimeToLive

时间:2011-06-21 08:10:38

标签: networking terminology ttl

http://searchnetworking.techtarget.com/definition/time-to-live

从这篇文章中,我对这个主题的定义感到困惑。 有没有人有机会帮助我找不到更好的事情呢?

STAV。

----------------------------------


编辑:

我试图从同一台计算机上发送按摩给我自己。 当我将TTL值设置为0时,我发送的包仍然可以找到我。这是为什么? 这是代码:

btw,发送方法中的这一行。

server.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, 0);


    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Threading;
    class MAIN
    {
        public static MulticastOption MulticastOption;
        private static MulticastOption CreateGroup()
        {
            MulticastOption = new MulticastOption(IPAddress.Parse("224.100.0.1"));
            return MulticastOption;
        }
        private static void Receive()
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
            EndPoint ep = (EndPoint)iep;
            sock.Bind(iep);
            sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, MulticastOption);
            //
            byte[] data = new byte[1024];
            new Thread(new ThreadStart(Send)).Start();
            int recv = sock.ReceiveFrom(data, ref ep);
            String stringData = Encoding.ASCII.GetString(data, 0, recv);
            Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
            sock.Close();
        }


   private static void Send()
    {
        Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9051);
        IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9050);
        server.Bind(iep);
       server.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("224.100.0.1")));
     server.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.MulticastTimeToLive, 0);
        server.SendTo(Encoding.ASCII.GetBytes("This is a test message"), iep2);
        server.Close();
    }
    public static void Main(String[] args)
    {
        CreateGroup();
        Receive();
        Console.ReadKey();
    }
}

1 个答案:

答案 0 :(得分:0)

客户端计算机在生成数据包时设置 TTL值,以指示允许数据包通过的最大跳数。

每次数据包通过路由器时,路由器都会减少 TTL值。

如果TTL值达到零,路由器将丢弃数据包并返回ICMP“超出跳数”错误消息。

TTL字段的主要好处是在发生路由循环时阻止数据包永远跳转,即网络故障导致数据包在同一组路由器周围和周围反弹