How to listen to all the ports while using UDP (MF 3.0)?

Hello Guys,

I am currently doing a project which needs my program to receive data from a data logger.
Some of you might have seen the related entry couple days ago.

I thought I succeeded to receive the data from the data logger, but anyway, I made a really stupid mistake. :-[

I investigated some code on the internet.
some websites say that by setting the following item to 0, my socket will listen to all the ports.

IPEndPoint(IPAddress.Any, 0)

However, as I set this to 0 and monitored the packet by WinDump, my socket received nothing. :o

could you please help me? :-[

I think that is not possible. You can only listen to one port with a single socket.

If your datalogger broadcasts its data, it will do so to a fixed destination port.

Hello Wouter~!
thanks again for answering.

last time you suggested me to receive the data via the sending port.

for example, in this picture, the sending port is 51159.

how do I receive the data via port 51159 in my program? (every single time,the sending port changes, so I don’t really know how to fix that sending port)

I am completely puzzled by the “UDP socket”.

So IP .15 is your FEZ and .55 is your datalogger? The port 8023 is fixed on the datalogger?


The data logger only communicates via port 8032. (data logger ip:

I am actually using the VS2008 SP1 MF3.0 Emulator to send this first via ip

Bind your udp socket to a fixed port:

udp.Bind(new IPEndPoint(IPAddress.Any, 8030));

This way, the udp packets will be sent from this fixed port, and the datalogger will always answer to port 8030.

Send data to logger:

udp.SendTo(buffer, dataloggerEP);

Receive data from logger (f.e. from other thread):

while (udp.Available > 0)
    int bytesReceived = udp.Receive(buffer);

Additional note: by binding your socket, you will also receive UDP broadcast messages to port 8030.

So for security reasons you might want to use ReceiveFrom instead of Receive. This way you will receive the EndPoint from where the data comes, and you can compare that EndPoint with the dataloggerEP…

Further question: why are you still on netmf 3? Seems you have (or are building) a commercial product, but why not move to something that is more supportable from the community? Luckily the things you’re talking about right now are generic networking things, but you could find yourself in a sticky situation if you start asking behavioural questions since most are on 4.1 (and hanging out for 4.2)