Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending data over UDP
#3
(Oct-19-2017, 11:41 AM)Larz60+ Wrote: The ten may be the number base.
Check to see if you need to be sending a tuple

check out: http://www.wellho.net/resources/ex.php4?..._client.py

That example sends a string, which I don't have a problem with. There are some vague examples that send binary or hex by using struct to pack but I can't get any of them to work. I think it must be something in Matlab, but I have it working fine with a C program doing the same thing.

This is the segment of code:
for i in range(0, 21):
    print('Sending command {} to {}.' .format('A', host_address))
    host_socket.sendto('A', host_address)      # Accept command.
    host_socket.sendto('\n', host_address)
#    val = i
#    val = bytes(i)
#    val = struct.pack('!i', i)
    val = str(i)
#    val = bytearray()
#    val.append(i)
    print('Sending value {} to {}.' .format(val, host_address))
    host_socket.sendto(val, host_address) # Value.
    host_socket.sendto('\n', host_address)

print('Sending command {} to {}.' .format('Q', host_address))
host_socket.sendto('Q', host_address)      # Quit command.
host_socket.sendto('\n', host_address)
The commented out bits are what I have tried. Surely converting to a string should work at the very least!
Reply


Messages In This Thread
Sending data over UDP - by alidaf - Oct-19-2017, 09:39 AM
RE: Sending data over UDP - by Larz60+ - Oct-19-2017, 11:41 AM
RE: Sending data over UDP - by alidaf - Oct-19-2017, 12:47 PM
RE: Sending data over UDP - by Larz60+ - Oct-19-2017, 03:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python + PHP. Sending data from "Moodle" (php) to python CGI-script and get it back stanislav 0 1,586 May-07-2022, 10:32 AM
Last Post: stanislav

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020