import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 49152
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
try:
data, addr = sock.recvfrom(4000) # buffer size is 4000 bytes
print(data.decode("utf-8") )
except:
print("Overflow")
//Transmitting program
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
address = ('127.0.0.1', 49152)
sock.sendto('Test Message', address)
sock.close()
I am using these from Python based PostgreSQL stored functions, but was hoping to use Harbour instead.
The main advantage of UDP versus TCP or file logging, is that if you don't listen to messages, no extra disk space is used and there is very little performance loss. That is also the way DebugView works by the way.