Udp time out option : Udp « Network « C# / CSharp Tutorial






using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
   public static void Main()
   {
      byte[] data = new byte[1024];
      string input, stringData;
      int receivedDataLength;
      IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);

      Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);

      int sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
      Console.WriteLine("Default timeout: {0}", sockopt);
      server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000);
      sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
      Console.WriteLine("New timeout: {0}", sockopt);

      server.Close();
   }
}








33.10.Udp
33.10.1.UDP multi-cast
33.10.2.Udp time out option
33.10.3.new UdpClient(5555) Receive