Sending UDP Packet in C#

Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPAddress serverAddr = IPAddress.Parse(“192.168.2.255”); IPEndPoint endPoint = new IPEndPoint(serverAddr, 11000); string text = “Hello”; byte[] send_buffer = Encoding.ASCII.GetBytes(text ); sock.SendTo(send_buffer , endPoint);

How to set the don’t fragment (DF) flag on a socket?

You do it with the setsockopt() call, by using the IP_DONTFRAG option: int val = 1; setsockopt(sd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val)); Here’s a page explaining this in further detail. For Linux, it appears you have to use the IP_MTU_DISCOVER option with the value IP_PMTUDISC_DO (or IP_PMTUDISC_DONT to turn it off): int val = IP_PMTUDISC_DO; setsockopt(sd, … Read more

Structure size so big, need optimization

Your Test structure is quite large, 588,000 bytes, which might be too large for automatic storage. Make it static should solve the problem, but will make your code non reentrant and definitely not thread safe. If the problem is with the maximum packet size, you must break the transmission into smaller packets. Use a smaller … Read more