socket.send() returns

charliehubbard at my-deja.com charliehubbard at my-deja.com
Wed Dec 22 14:50:29 EST 1999


# Echo server program

Here is some code from the ftplib module.  I'm trying to write a server
that is similiar to an FTP daemon.  I also need to send binary files
and text files over a socket connection.  In the following procedure
the return of send is tested to break out of the infinite loop.  When
would this condition be satisfied?  When would the socket.send()
ever return ''?

thanks
charlie

#---code
def retrbinary(self, cmd, callback, blocksize=8192):
	'''Retrieve data in binary mode.
	The argument is a RETR command.
	The callback function is called for each block.
	This creates a new port for you'''
	self.voidcmd('TYPE I')
	conn = self.transfercmd(cmd)
	while 1:
		data = conn.recv(blocksize)
		if not data:
			break
		callback(data)
	conn.close()
	return self.voidresp()


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list