Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Udp listen example
-
Hello,
I am new here coming from Codea.
There are no access to an udp stream in Codea but looks like it is possible in Pytonista.
Does anyone have an example to start out with ?
I see the snipperts in the documentation, but from previous experience with Python, I know that some kind of threading is needed, so any help to get started is appreciated.
Re Peter -
I use UDP protocol in a remote controlled tank app.
https://gist.github.com/GuyCarver/4141545
and
https://gist.github.com/GuyCarver/4142882 -
Thanks for the links.
I have tried to strip your code to the udp stuff only but did not succeed to make something usable with threading.
However I found another more straight forward solution.
I define a socket like this:import socket
import struct
port = 49020
s = socket.socket(socket.AF_INET. socket.SOCK_DGRAM)
s.bind(("", port))and in the draw() of a scene listening and unpacking floats:
d = s.recvfrom(1024)
bytes = d[0]
test_float_ex = struct.unpack('f', bytes[9]+bytes[10]+ bytes[11]+bytes[12])The code is blocking, but since I need the float values to drive gauges, I think it must be valid.
Have to check the frame rate at some point though .....By the way, how do you put formatted code in the forum ?
Re Peter
-
How do you put formatted code in the forum?
Use HTML < pre > and < /pre > tags.