Home All Groups Group Topic Archive Search About

UDPClient Broadcast Receive Error with PPPOE

Author
24 Mar 2007 12:50 PM
greenxiar
My Computer is Win2K3 R2, Code is:

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace TechUDPBroadcast {
    class Program {
        static void Main(string[] args) {
            const string addr = "224.1.3.99";
            const int prt = 12799;

            UdpClient udpc = new UdpClient();
            udpc.Client.SetSocketOption(SocketOptionLevel.Socket,
                                        SocketOptionName.ReuseAddress,
true);
            udpc.Client.Bind(new IPEndPoint(IPAddress.Any, prt));
            udpc.EnableBroadcast = true;

            udpc.JoinMulticastGroup(IPAddress.Parse(addr));

            ManualResetEvent abort = new ManualResetEvent(false);
            WaitHandle[] evs = new WaitHandle[2];
            evs[0] = abort;
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate {
                while (true) {
                    IAsyncResult asy = udpc.BeginReceive(
                                new AsyncCallback(delegate(IAsyncResult
iasy) {
                        IPEndPoint rp = null;
                        byte[] recv = udpc.EndReceive(iasy, ref rp);
                        Console.Write(".");
                    }), null);
                    evs[1] = asy.AsyncWaitHandle;
                    if (WaitHandle.WaitAny(evs) == 0) return;
                }
            }));
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate {
                for (int i = 0; i < 1000; i++) {
                    udpc.Send(new byte[] { 0x1, 0x2 }, 2,
                                    new IPEndPoint(IPAddress.Parse(addr),
prt));
                    Console.Write("+");
                    Thread.Sleep(1000);
                    if (abort.WaitOne(0, false)) return;
                }
            }));
            Console.ReadKey();
            Abort.Set();
        }
    }
}
When my computer is single network connection(Local Network),
the code works fine. My problem is, when i connect the Internet with PPPOE,
the UDPClient can not receive the broadcasting data!

Why?

greenxiar

Author
24 Mar 2007 4:55 PM
Peter Duniho
On Sat, 24 Mar 2007 05:50:01 -0700, greenxiar <greenx***@hotmail.com> 
wrote:

> [...]
> When my computer is single network connection(Local Network),
> the code works fine. My problem is, when i connect the Internet with 
> PPPOE, the UDPClient can not receive the broadcasting data!

Broadcast datagrams are not routable over the Internet (and for good 
reason, if you think about it).

You'll need to use multicast or send the datagram directly to a given IP 
address if you expect the client to receive any data over the Internet.
Author
24 Mar 2007 7:36 PM
greenxiar
When the app is running at local network(Internet not connected),
the sending and receiving are good.
Then i launch the internet connection, the app stop receiving immediately.
The data packages are sent to both Local and Internet
(In Netmon.exe i can see it). Why UdpClient stop receiving?
What happened when i connect the internet?

Show quote
"Peter Duniho" <NpOeStPe***@nnowslpianmk.com> дÈëÏûÏ¢
news:op.tppdbfiz8jd0ej@petes-computer.local...
> On Sat, 24 Mar 2007 05:50:01 -0700, greenxiar <greenx***@hotmail.com>
> wrote:
>
>> [...]
>> When my computer is single network connection(Local Network),
>> the code works fine. My problem is, when i connect the Internet with
>> PPPOE, the UDPClient can not receive the broadcasting data!
>
> Broadcast datagrams are not routable over the Internet (and for good
> reason, if you think about it).
>
> You'll need to use multicast or send the datagram directly to a given IP
> address if you expect the client to receive any data over the Internet.
Author
24 Mar 2007 8:02 PM
Peter Duniho
On Sat, 24 Mar 2007 12:36:16 -0700, greenxiar <greenx***@hotmail.com> 
wrote:

> When the app is running at local network(Internet not connected),
> the sending and receiving are good.
> Then i launch the internet connection, the app stop receiving 
> immediately.
> The data packages are sent to both Local and Internet
> (In Netmon.exe i can see it). Why UdpClient stop receiving?
> What happened when i connect the internet?

Sorry...I misunderstood and thought you were trying to send over the PPPOE 
connection.

Just to make sure I have things straight: you have a UDP client receiving 
UDP broadcast datagrams; it works fine when you are not connected to the 
Internet, but when you make a connection to the Internet using PPPOE, it 
stops receiving the broadcast datagrams.

If so, I suspect it is still related to the fact that datagrams can't be 
routed over the Internet.  It sounds as though the network adapter on the 
computer, once PPPOE is connected, treats all communications as though 
they are over the Internet.  Why this should be exactly I can't say for 
sure, not being that familiar with PPPOE.  Maybe someone else has a better 
answer.

You may get some insight by using ipconfig to display the network 
configuration for your network adapter, to see what happens to the local 
IP address and routing/gateway information.  That may help you see what 
changes that causes the broadcasts to be blocked.  Whether that would lead 
to a solution, I don't know...if you are running into a fundamental change 
in the network configuration that blocks the datagrams, you may be stuck 
with the same limitations that exist over the Internet proper.

Pete

AddThis Social Bookmark Button