omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    4
    2786
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • macnfly
      macnfly last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Gcarver166
        Gcarver166 last edited by

        I use UDP protocol in a remote controlled tank app.
        https://gist.github.com/GuyCarver/4141545
        and
        https://gist.github.com/GuyCarver/4142882

        1 Reply Last reply Reply Quote 0
        • macnfly
          macnfly last edited by

          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

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            How do you put formatted code in the forum?

            Use HTML < pre > and < /pre > tags.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors