See Also

Udp Class  | Udp Members

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

See Also Languages PowerTCP SSL Sockets for .NET

MulticastTimeToLive Property

Dart.PowerTCP.SslSockets Namespace > Udp Class : MulticastTimeToLive Property

Gets and sets the IP multicast time-to-live used when datagrams are sent to multicast addresses.

[Visual Basic]
<DescriptionAttribute("Gets and Sets the IP multicast time-to-live used when datagrams are sent to multicast addresses.")> <CategoryAttribute("Socket Options")> <DefaultValueAttribute()> Public Property MulticastTimeToLive As Integer
[C#]
[DescriptionAttribute("Gets and Sets the IP multicast time-to-live used when datagrams are sent to multicast addresses.")] [CategoryAttribute("Socket Options")] [DefaultValueAttribute()] public int MulticastTimeToLive {get; set;}
[C++]
[DescriptionAttribute("Gets and Sets the IP multicast time-to-live used when datagrams are sent to multicast addresses.")] [CategoryAttribute("Socket Options")] [DefaultValueAttribute()] public: __property int get_MulticastTimeToLive(); public: __property void set_MulticastTimeToLive(    int value );
[C++/CLI]
[DescriptionAttribute("Gets and Sets the IP multicast time-to-live used when datagrams are sent to multicast addresses.")] [CategoryAttribute("Socket Options")] [DefaultValueAttribute()] public: property int MulticastTimeToLive {    int get();    void set (int value); }

Return Type

An integer value representing the time-to-live value used when datagrams are sent to multicast addresses.

Remarks

The Udp.MulticastTimeToLive property specifies the number of routers (hops) that multicast datagrams are permitted to pass through before expiring on the network. For each router (hop), this property is decremented by 1. When this property reaches 0, each multicast datagram expires and is no longer forwarded through the network to other subnets.

Example

The following example demonstrates using multicasting functionality to create a simple chat client.

[Visual Basic] 

' The IPAddress representing the multicast address.
Private add As System.Net.IPAddress = System.Net.IPAddress.Parse("239.255.255.254")

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ' Allocate a socket for listening for datagrams.
   Udp1.Open("MyHost", 1111)

   ' Join the specified multicast group.
   Udp1.JoinMulticastGroup(add)

   ' Specify an interface to use for multicasting (assuming the host has multiple interfaces)
   Udp1.MulticastInterface = System.Net.IPAddress.Parse("192.168.1.2")

   ' Increase the datagram TTL for multicasting
   Udp1.MulticastTimeToLive = 2

   ' Begin asynchronously receiving data
   Dim buffer(Udp1.BufferSize) As Byte
   Udp1.BeginReceive(buffer)
End Sub

Private Sub Udp1_EndReceive(ByVal sender As Object, ByVal e As DatagramEventArgs) Handles Udp1.EndReceive
   ' Data received. Display
   txtData.Text += e.Datagram.ToString() + vbCrLF

   ' Begin asynchronously receiving data
   Dim buffer(Udp1.BufferSize) As Byte
   Udp1.BeginReceive(buffer)
End Sub

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
   ' Send button clicked. Send the contents of txtSend.
   Udp1.Send(txtSend.Text, add.ToString(), 1111)
End Sub

Private Sub cmdLeave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLeave.Click
   ' Leave group button clicked. Leave the group.
   Udp1.LeaveMulticastGroup(add)
End Sub

[C#] 


// The IPAddress representing the multicast address.
private System.Net.IPAddress add = System.Net.IPAddress.Parse("239.255.255.254");

private void Form1_Load(object sender, System.EventArgs e)
{
  
// Allocate a socket for listening for datagrams.
  
udp1.Open("MyHost", 1111);

  
// Join the specified multicast group.
  
udp1.JoinMulticastGroup(add);

  
// Specify an interface for multicasting (assuming the host has multiple interfaces)
  
udp1.MulticastInterface = System.Net.IPAddress.Parse("192.168.1.2");

  
// Increase the datagram TTL for multicasting
  
udp1.MulticastTimeToLive = 2;

  
// Begin asynchronously receiving data
  
byte[] buffer = new byte[udp1.BufferSize];
  udp1.BeginReceive(buffer);
}

private void udp1_EndReceive(object sender, DatagramEventArgs e)
{
  
// Data received. Display
  
txtData.Text += e.Datagram.ToString() + "\r\n";
              
  
// Begin asynchronously receiving data
  
byte[] buffer = new byte[udp1.BufferSize];
  udp1.BeginReceive(buffer);
}

private void cmdSend_Click(object sender, System.EventArgs e)
{
  
// Send button clicked. Send the contents of txtSend.
  
udp1.Send(txtSend.Text, add.ToString(), 1111);
}

private void cmdLeave_Click(object sender, System.EventArgs e)
{
  
// Leave group button clicked. Leave the group.
  
udp1.LeaveMulticastGroup(add);
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Udp Class  | Udp Members


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.