Mar-12-2021, 01:11 AM
(This post was last modified: Mar-12-2021, 01:11 AM by supuflounder.)
(Mar-11-2021, 09:09 PM)pacmyc Wrote: Hi.
I have a device that send some data via broadcast to port 0 in my network.
I can listen to the traffic with wireshark.
Is it possible to get Python to listen to port 0 for UDP packets?
Several things to note:
- You should not use Port 0. This is a bad selection. You want a port number as specified in the document RFC6335 It says,
Quote:Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535); the difference uses of these ranges is described in [RFC6335]. According to Section 8.1.2 of [RFC6335], System Ports are assigned by the "IETF Review" or "IESG Approval" procedures described in [RFC8126]. User Ports are assigned by IANA using the "IETF Review" process, the "IESG Approval" process, or the "Expert Review" process, as per [RFC6335]. Dynamic Ports are not assigned.
You should only use port numbers in the "User Ports" range.
- UDP is a particularly poor protocol to use. In general, you should always use TCP/IP. It is slightly more complex, but TCP/IP is as reliable as a physical wire connecting the two endpoints. In UDP, you never know if your message arrived, and the receiver never knows if you sent a message. With TCP/IP, it is worth the extra effort, because every byte you send will be received, although not always as a single message (it can be split across multiple messages). And if there is a failure, both ends of the communication get a notification. It is worth expending the extra effort to learn to use TCP/IP; once you have done this, you "own" the concept of reliable communication. UDP packets can be dropped, you can receive the same packet more than once, and you can receive packets out of order. Just about the worst possible way to do communications, and you have to be prepared for all of them. Oh, yes, the packet may be truncated without any indication it has been shortened, so there is an upper bound on packet size which you have to be prepared to live with. Send a longer packet, and it may not all get there, and neither you nor the receiver will know it was truncated.