Windows Form App - Send UDP packet

I always have problems by sending UDP packets.

I want to send just a simple UDP packet from my windows form applikation.

I receive the data on my G120HDR board with this code:

Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress ip = new IPAddress(new byte[] { 192, 168, 1, 100 });
int port = 50828;
IPEndPoint endPoint = new IPEndPoint(ip, port);

while (true)
       while (socket.Poll(200000, SelectMode.SelectRead))
              if (socket.Available > 0)
                   byte[] inBuf = new byte[socket.Available];
                   EndPoint recEndPoint = new IPEndPoint(IPAddress.Any, 0);
                   socket.ReceiveFrom(inBuf, ref recEndPoint);
                   Debug.Print(new String(Encoding.UTF8.GetChars(inBuf)));

So what I want, is that I can send a simple UDP packet (just “hello world”) to my G120HDR every time I press a button.
Someone who can help me?

Check out Codeshare my friend:


But this is not from a windows form application :frowning:

I can’t do it in the same way.