Example does not function as it intended
Leastell opened this issue · comments
I went into detail on this issue on my StackOverflow question regarding the topic, which can be found here. At the time of this issue report, it has not been answered.
Any idea why the examples would be behaving this way? Is there some change that could be made to prevent them from happening in the future?
I am attempting to get the open-dis python package running correctly on my machine. I am running Python 3.8.
Using pip, I compile the package from it's source as so:
pip install .
After that, as instructed in the documentation. I run
python dis_receiver.py
I am immediately met with this error:
Created UDP socket 3001 Traceback (most recent call last): File "dis_receiver.py", line 40, in <module> recv() File "dis_receiver.py", line 27, in recv data = udpSocket.recv(1024) # buffer size in bytes socket.timeout: timed out
I don't really understand why this is happening given that I have changed absolutely nothing about the documented example process. Any idea why this would be happening?
Hi Laif, the reason you are receiving this error is the line here
You can replace the 3
there:
udpSocket.settimeout(3) # exit if we get nothing in this many seconds
with another value to defer the timeout. But this brings about another issue. It seems you may only be running the receiver. For this example to work, you should also run the dis_sender.py at the same time. The receiver code simply awaits the sending of the DIS packets from another source, before it does anything exciting.
I hope this helps. If you have any more questions, feel free to email me.
V/R,
Conner
The timeout is manually set to 3ms. This is nowhere near enough time in my opinion to properly test the system, simply extend that and you won't get this error. I would recommend making this change permanent in a future update.
Note: Thanks for your response Conner! Funnily enough I was just typing out the solution above when your comment popped up. Not sure why I didn't notice that to begin with.
Understood! If it help to know, I suggest implementing your socket in a way that either:
- Doesn't block execution, or
- lives in its own thread for receiving data as to allow your remaining code to keep going.
If you did want your socket to time out in this way, you should wrap your receive code in a try/catch
block, which allows you to handle the error instead of it dumping the execution entirely:
try:
data = udpSocket.recv(1024) # buffer size in bytes
except socket.timeout:
print("No data was found in the allotted time")
As this is only an example, I wouldn't put too much weight into using the protocol in this manner (i.e. the example code), necessarily. I am interested to know what you are using DIS for. No obligation of course, but if you wanted to shoot me an email about your use of DIS, I would be more than happy to help give you some of my thoughts and ideas.