I've written a new IRC client to which I just added the DCC SEND part, therefore supporting direct file transfer for both users of the app. Nothing, fancy, I'm using the irc python library to power the client and Django for the GUI. The great miniupnpc lib takes care of port forwarding. However, whilst the file is properly being sent/received, the speed is absolutely HORRENDOUS : 20 KB/s approximatively. To test the server, I sent a package using Hexchat : the upload speed was the maximal theoretical bandwidth speed (in other words excellent). I tried looking for a buffer of some sort I may have missed. In the end, I must say I have absolutely no idea why my upload speed is so crappy and need some insight. Here is the relevant part of my upload script.
def on_dcc_connect(self, c, e):
t = threading.Timer(0, upload_monitoring, [self, c])
t.start()
log("connection made with %s" % self.nickname).write()
self.file = open(self.filename, 'rb')
self.sendBlock()
def sendBlock(self):
if self.position > 0:
self.file.seek(self.position)
block = self.file.read(1024)
if block:
self.dcc.send_bytes(block)
self.bytesSent = self.bytesSent + len(block)
else:
# Nothing more to send, transfer complete.
self.connection.quit()
def on_dccsend(self, c, e):
if e.arguments[1].split(" ", 1)[0] == "RESUME":
self.position = int(e.arguments[1].split(" ")[3])
c.ctcp("DCC", self.nickname, "ACCEPT %s %d %d" % (
os.path.basename(self.filename),
self.eport,
self.position))
def on_dccmsg(self, connection, event):
data = event.arguments[0]
bytesAcknowledged = struct.unpack("!Q", data)[0]
if bytesAcknowledged < self.bytesSent:
return
elif bytesAcknowledged > self.bytesSent:
self.connection.quit()
return
self.sendBlock()
The send_bytes(block)
method is the basic socket.send()
method. When I increase the buffer of file.read(), I get struct.pack error, because the client's block reception acknowledgment (also struct.pack) is not properly read by my send script: data not of bytes length 8. Is it the file.read buffer that has to be changed? If so, why is the bytes received acknowledgment not the same at the sender's side as downloader's side? If not, where should I look to improve the upload speed?