This file is part of eRCaGuy_hello_world: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world
- *****+ EXCELLENT example code, UDP sending and receiving examples, multicast, etc: https://wiki.python.org/moin/UdpCommunication
- TCP example code: https://wiki.python.org/moin/TcpCommunication
- https://docs.python.org/3/library/select.html#poll-objects - select — Waiting for I/O completion — Python 3.11.4 documentation [GS notes: how to do Ethernet polling in Python: create a socket, call
poll.register(fd)to pass in the socket fd file descriptor, then callpoll.poll([timeout_ms])to get back an iterable tuple of(fd, event)2-tuples telling me which socket file descriptors are ready to be read and have data right now!; how to do ethernet socket polling in Python--see my notes to the left!]
From: https://wiki.python.org/moin/UdpCommunication
-
UDP sender ("client"):
import socket UDP_IP = "127.0.0.1" UDP_PORT = 5005 MESSAGE = b"Hello, World!" print("UDP target IP: %s" % UDP_IP) print("UDP target port: %s" % UDP_PORT) print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
-
UDP receiver ("server")
import socket UDP_IP = "127.0.0.1" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print("received message: %s" % data)
From: https://wiki.python.org/moin/TcpCommunication
- TCP sender ("client"): see link above.
- TCP receiver ("server"): see link above.