user494461
user494461

Reputation:

why is the UDPclient multicast not working?

public void send_multicast(string message)
    {
        UdpClient c = new UdpClient(10102);
        Byte[] sendBytes = Encoding.ASCII.GetBytes(message); 
        IPAddress m_GrpAddr = IPAddress.Parse("224.0.0.1");
        IPEndPoint ep = new IPEndPoint(m_GrpAddr,10102);   
        c.MulticastLoopback=true;
         c.JoinMulticastGroup(m_GrpAddr);
        c.Send(sendBytes,sendBytes.Length,ep);
        Console.WriteLine(message);
    }

    public string recv_multicast()
    {
        Console.WriteLine("was here");
        String strData = "";
        //String Ret = "";
        ASCIIEncoding ASCII = new ASCIIEncoding();
        UdpClient c = new UdpClient(10101);

        // Establish the communication endpoint.
        IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 10101);
         IPAddress m_GrpAddr = IPAddress.Parse("224.0.0.1");

         c.JoinMulticastGroup(m_GrpAddr);
            Byte[] data = c.Receive(ref endpoint);
            strData = ASCII.GetString(data);
            //Ret += strData + "\n";

        return strData;
    }

is there anything wrong with the ports?

the recv method is getting blocked but is not receiving the message?

In wireshark I can see the message going from local addr port 10102 to 224.0.0.1 dest_port 0, but the recv is not getting the msg from the multicast addr.

BTW I am running both instances on the same computer. reference : http://msdn.microsoft.com/en-us/library/ekd1t784.aspx

**Got the solution:In send routine

IPEndPoint ep = new IPEndPoint(m_GrpAddr,10102); 

should be

IPEndPoint ep = new IPEndPoint(m_GrpAddr,10101);

the port of receiving**

Upvotes: 3

Views: 4984

Answers (1)

Polynomial
Polynomial

Reputation: 28316

You need to enable multicast loopback in order to recieve packets sent by yourself.

http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.multicastloopback.aspx

You should use JoinMulticastGroup on the server side as well as the client side. If that fails, you can also try using Wireshark (google it) to see if the packets are actually sent.

Upvotes: 1

Related Questions