Socket options in C#

Socket options determine the behavior of an instance of the Socket class. Some socket options apply only to specific protocols while others apply to all types. Members of the SocketOptionLevel enumeration specify which protocol applies to a specific socket option.

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class SocketOptionNameSample
    public static void Main()
        IPAddress ip = IPAddress.Parse("");
        IPEndPoint ep = new IPEndPoint(ip, 9999);
        Socket skt = new Socket(AddressFamily.InterNetwork,
        SocketType.Dgram, ProtocolType.Udp);
        SocketOptionName.SendTimeout, 5000);
            Byte[] req = Encoding.ASCII.GetBytes("Test");
            skt.SendTo(req, ep);
        catch (Exception e)
            Console.WriteLine("Error: " + e.Message);

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.