UDP Enable Port Sharing

5 次查看(过去 30 天)
Greg
Greg 2017-2-21
回答: Greg 2017-3-2
I have one PC (call it the brain) create a separate UDP object for a connection to each other PC (call them the body parts) on my network. I'm trying to use EnablePortSharing to make things easier. With port sharing on, all incoming traffic to the brain arrives on the first UDP object I call fopen() on, no matter which body part sent the message. Outgoing traffic behaves as expected.
Is this a bug, or me simply not understanding what port sharing is actually supposed to do? If it's me, can anybody explain how it actually works (or more, why)? Perhaps an example of when it's useful?

回答(1 个)

Greg
Greg 2017-3-2
Tech support contacted me directly about this issue, so I'll post what I received from them:
After discussing with my colleagues, I have confirmed that the behavior you are observing using the "EnablePortSharing" property is expected.
The 'EnablePortSharing' option when set to 'on' would allow two separate applications (for example MATLAB and a 3rd party application, or two MATLAB processes) to bind to the same Ethernet interface and port in order to both receive the same UDP packets that are transmitted in broadcast mode by another application or a separate device/computer.
If the UDP packets are sent in unicast mode (to a specific IP and port), only one of the applications listening on that port will receive the UDP packets (as seen in this case).
In MATLAB, to broadcast / send UDP packets to all computers in the same subnet to port 8888, we would need to specify the subnet broadcast IP as the remote host (in this case '192.168.1.255') when creating the UDP object:
u = udp('192.168.1.255', 'RemotePort', 8888) Also, please note that to get information on the sender of the UDP packet (IP address and port), you can use the following syntax of the "fread" function:
[A,count,msg,datagramaddress,datagramport] = fread(obj);

类别

Help CenterFile Exchange 中查找有关 Peripherals 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by