[Tutor] error: (10054, 'Connection reset by peer')

Patrick Kirk patrick@kirks.net
Mon Jun 23 05:26:03 2003


Hi all,

I'm coding a Gnutella daemon and it crashes when a peer resets the 
connection.

I've tried to set up logging to catch the problem but the function dies 
before anything gets logged.

How should I handle this?

createSocket() reads as follows:

# Create listener and process input
def createSocket():
	sockobj = socket(AF_INET, SOCK_STREAM)		# makes socket object
	sockobj.bind((myHost, myPort))			# binds it to server and port
	sockobj.listen(50)				# number of connections allowed
	
	
	while 1:					# listen 'til process killed
		connection, address = sockobj.accept()	# waiting for connection
		data = connection.recv(1024)		# read next line on client socket
		remoteIP = address[0]			# address is a tuple
		if not data: break
		handshake0 = 'GNUTELLA CONNECT/0.6'
		handshakeRequest = data.find(handshake0)
		request = 'GET '
		fileRequest = data.find(request)
		if fileRequest > -1:
			connection.send('GNUTELLA/0.6 503 Full\r\n') # Gently say I can't help.
			connection.close()  # Rude but how does one say NO?
			logGETs = open("GETsLog.txt", "a")
			logGETs.write(remoteIP)
			logGETs.write('\t')
			logGETs.write(data)
			logGETs.write('\r\n')
			logGETs.close()

		
		elif handshakeRequest > -1:
			connection.send('GNUTELLA/0.6 200 OK\r\n' ) # lets see what reply we get
			if not data: break		# send reply line to client
			logHandshake = open("handshakeLog.txt", "a")
			logHandshake.write(remoteIP)
			logHandshake.write('\t')
			logHandshake.write(data)
			logHandshake.write('\r\n')
			logHandshake.close()

		elif error:
			logOthers = open("othersLog.txt", "a")
			logOthers.write(' Error \r\n')
			logOthers.close()
			break

	
	    	else:
			connection.send('GNUTELLA/0.6 503 Full\r\n') # #Gently say I can't help.
			connection.close()
			logOthers = open("othersLog.txt", "a")
			logOthers.write(remoteIP)
			logOthers.write('\t')
			logOthers.write(data)
			logOthers.write('\r\n')
			logOthers.close()

The error is as follows:

   File "C:\Documents and Settings\patrick\Desktop\p2pdev\server.py", 
line 16, in createSocket
     data = connection.recv(1024)		# read next line on client socket
   File "<string>", line 1, in recv
error: (10054, 'Connection reset by peer')
-- 

Best regards,


Patrick Kirk
Mobile: 07876 560 646