TTL Value - TimeToLive
http://searchnetworking.techtarget.com/definition/time-to-live
From this article, im Confused about the defanition about this subject. is there any chance someone help me undestand better whats going on?
stav.
----------------------------------
EDIT:
i tried to send massage to my self from the same computer. when i set the TTL value to 0, the pa开发者_开发知识库ck i send still get to me. why is that? here is the code:
btw,this line in the Send Method.
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();
}
}
Client machines set the TTL value when a packet is generated, to indicate the maximum number of hops the packet is permitted to go through.
Each time a packet passes through a router the router will decrement the TTL value.
If the TTL value reaches zero, the router will drop the packet and return an ICMP "hop count exceeded" error message.
The main benefit of the TTL field is to stop packets bouncing around forever in the event of a routing loop, i.e. a network fault that causes packets to bounce around and around between the same set of routers.
精彩评论