none
display UDP messages RRS feed

  • Question

  • HI

    i have created a program that sends data using UDP
    i need to test whether the messages are going out properly

    so i want to make a simple console app that will listen for UDP messages and display them in the console
    here is my code so far:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;

    namespace recieveUDP
    {
        class Program
        {
            static void Main(string[] args)
            {
                UdpClient udps = new UdpClient();
                IPEndPoint groupeds = new IPEndPoint(IPAddress.Any, 9998);
                

                while (true)
                {
                    byte[] br = udps.Receive(ref groupeds);
                    string rmess = Encoding.ASCII.GetString(br);
                    Console.WriteLine(rmess);
                }

                udps.Close();

            }
        }
    }

    the red text is where i get the following error:
    you must call the bind method before performing this operation

    udpclient doesn't have a bind operation though

    can anyone help with this?

    thanks in advance

    Saturday, August 16, 2008 1:48 PM

Answers

  •  
                UdpClient udps = new UdpClient();  
                IPEndPoint groupeds = new IPEndPoint(IPAddress.Any, 9998);  
                udps.Connect ( groupeds ); 

    AlexB
    • Marked as answer by jack 321 Thursday, August 21, 2008 2:58 AM
    Saturday, August 16, 2008 5:21 PM