I'm ruing into an Unterminated string error when receiving UDP packets on and from a local socket.
This is due to my messages being of various lengths, and my buffer size seemingly being insufficient (I've tried as much as 16k buffersize - which wasn't enough). Since I've read that buffers shouldn't be half that size to begin with, I've tried exploring other options, as using TCP sockets is not an option.
I came across the socket.makefile method, but have thus far failed to make it work with my UDP packets (all recipes making use of this used TCP sockets).
I've tried this:
from socket import socket, AF_INET, SOCK_DGRAM
def listen():
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(('localhost', 6667))
while True:
data = sock.makefile('rb', 0).readline()
log.debug(data)
js = json.loads(data.decode())
The problem is, nothing appears to be ever read (there are no log calls).
How do I make use of socket.makefile with UDP sockets? If it isn't possible to use it, since I'm sending the data from a process on the same machine, can I safely scale up my buffersize, since I know the data's origin?
