I write a little program that sends file from client to server trough udp socket connection.. the program works correctly but if the file I transfer is larger than 8192 kb the stream stops and the file I receive is corrupt..
How can I avoid this limitation?
server.py
host = ...
port = ...
filename = ...
buf = 2048
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
f = open(filename, 'wb')
block,addr = UDPSock.recvfrom(buf)
while block:
if(block == "!END"): # I put "!END" to interrupt the listener
break
f.write(block)
block,addr = UDPSock.recvfrom(buf)
f.close()
UDPSock.close()
client.py
host = ...
port = ...
filename = ...
buf = 2048
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
f = open(filename, 'rb')
block = f.read(buf)
while block:
UDPSock.sendto(block, addr)
block = f.read(buf)
UDPSock.sendto("!END", addr)
f.close()
UDPSock.close()
You still haven’t explained why you must use UDP – it simply isn’t designed for high volume data transfers as it doesn’t have any (simple) congestion management.
If you are sending VoIP then when not simply transmit at real-time, not “as fast as possible”?
FWIW, typical VoIP systems packetise the data into 20ms chunks or thereabouts. Hence if you’re using an voice codec like GSM which requires 13 kbps, you only need to chunk into 260 bits (~32 bytes) per packet, and send them every 0.02 seconds.