Example #1
0
def sendChunk(filepath):
	if diodeCommon.checkFileLock(filepath):
		return False
	serverIP = '192.168.1.140'
	#global serverIP
	s = socket.socket()	# Create a socket object
	host = serverIP		# Get local machine name
	port = 12345		# Reserve a port for your service.

	try:
		s.connect((host, port))
	except:
		print 'Cannot connect....'
		time.sleep(10)
		return False
	print 'Sending filename...'
	s.send(os.path.relpath(filepath, folderRoot)+'\n')

	f = open(filepath,'rb')
	print 'Sending...'
	l = f.read(1024)
	while (l):
		s.send(l)
		l = f.read(1024)
	f.close()
	print "Done Sending"
	s.shutdown(socket.SHUT_WR)
	#print s.recv(1024)
	s.close 
	return True