Main Site Documentation

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


#1

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? :-[


#2

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


#3

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


#4

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”.


#5

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


#6

Yes.

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

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


#7

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);


#8

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…


#9

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)