Beispiel #1
0
def client_thread(buff):
	global BUFFER, count
	count += 1

	ip_ob = IP.IP()
	my_ip = ip_ob.get_my_ip()
	#self.ip = my_ip
	#---------------------------------
	my_ip = master_ip1         # ip of master

	conn = buff[0]
	self = buff[1]
	used_port = 0
	file_server = ""
	
	#infinite loop so that function do not terminate and thread do not end.
	#here should be added a try catch block - to detect lost connecions or failed connections
	try :
		while True:
			'''here there will be the logic 
				* to respond to interconnection request from another tier2 server (this will be constant connections)
				* the other type of connection may be from clients.. this can be search request, 
				* each client will be connected to the client
				* each upload or download will be done by server initiating a new connection from and to client respectively
			'''
			#Receiving from client
			data = conn.recv(BUFFER)
			print "data ",data
			print data[:-1]
			#reply = 'OK...' + data


			# '7:' prefix for connection ... corresponding reply
			# '9:' search request ..   # inverted trie implementation
			# '15:' upload request from client
			if data[:-1] == '' :
				break
			elif data[:2] == '7:' :
				print 'New connection initiated; sending reply'
				message = '8:ACK'
				while  True:
					try :
						#Set the whole string
						conn.sendall(message)
					except socket.error:
						#Send failed
						print 'Send failed and retrying'
						continue
					finally :
						break
			elif data[:3] == '14:' :
				print 'Threaded implementation of file upload'
				used_port = self.PORT_Mapper.get_port()
				print "Get port = %d" %used_port
				self.PORT_Mapper.use_port(used_port)
				message = '15:port:' + str(used_port)
				file_server = FileServer.FileServer(used_port)
				file_server.setSharedDirectory(files_path)
				file_server.startServer()

				print "sending to client : ",message
				while  True:
					try :
						conn.sendall(message)
					except socket.error:
						print 'Send failed and retrying'
						break
					finally :
						break
						#break
			elif data[:3] == '16:' :
				#Threaded implementation of file upload
				print 'updation of trie after file upload'
				self.PORT_Mapper.free_port(used_port)
				message = '17:ACK:' + str("none")
				file_server.stopServer()
				filename_key = data[data.rfind(':')+1:]
				print "filename_key",filename_key
				#update_trie(self, filename)


				masters_list = get_masters_from_persistence("server 2:LIST_OF_MASTERS")
				list_of_masters = masters_list.split()
				print "list of masters :" , list_of_masters,"PPPPPPPPP"

				for master_ip in list_of_masters:
					update_trie(self, filename_key, master_ip)       # later not to store ip beacuse trie on master will just have the file names
					#tester(self,"666666")

				print "Updated trie in all masters"					
	
				while  True:
					try :
						#Set the whole string
						conn.sendall(message)
					except socket.error:
						#Send failed
						print 'Send failed and retrying'
						continue
					finally :
						count -= 1
						conn.close()
						break
			#elif data[:3] == '10:' :   
			#	print 'Threaded implementation of file upload'
			#	message = '11:IP_address:10.0.0.4'
			#	while  True:
			#		try :
			#			#Set the whole string
			#			conn.sendall(message)
			#		except socket.error:
			#			#Send failed
			#			print 'Send failed and retrying'
			#			continue
			#		finally :
			#			break

			elif data[:3] == '22:' :
				print "Pastry search protocol"
				filekey = data[data.rfind(':')+1:]
				print "filekey :",filekey
				step = 0
				for i in range(0,min(len(self.nodeid),filekey)):
					if(self.nodeid[i] != filekey[i]):
						break
					else:
						step += 1
				print "current matching steps :",step
				target_ip = client_back_process(self,conn,filekey,str(step))
				return target_ip

			elif data[:-1] == 'exit':
				print 'connection closed' 
				conn.close()
				break
			#conn.sendall(reply)
	except :
		conn.close()
	finally :
		conn.close()
Beispiel #2
0
 def start_file_server(self):
     self.client.file_server = FileServer.FileServer(self.client)
     self.client.file_server.start_server()
Beispiel #3
0
 def start_file_server(self):
     self.file_server = FileServer.FileServer(self)
     self.ip, self.port = self.file_server.start_server()
Beispiel #4
0
            client.WritePickleFile(obj, file)

    finally:
        client.UnlockFile(file, id)

    return return_item


if __name__ == "__main__":

    import FileServer
    import time
    import libtbx.load_env

    cmd = libtbx.env.under_dist("libtbx", "libtbx/server/StartServer.py")
    python_path = sys.executable

    if sys.platform == 'win32':
        os.spawnv(os.P_NOWAIT, python_path, (python_path, cmd))
    else:
        os.spawnvp(os.P_NOWAIT, python_path, (python_path, cmd))

    time.sleep(5)

    client = FileServer.GetServerClient()

    print client
    if client:
        print client.tester()
        #client.shutdown()
Beispiel #5
0
#! usr/bin/python3
import FileServer
import time

server = FileServer.FileServer()
while True:
    server.listen()
Beispiel #6
0

class ChatServer(dispatcher):
    def __init__(self, port):
        dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        # self.set_reuse_addr()
        self.bind(('', port))
        self.listen(5)
        self.users = {}
        self.main_channel = ListChannel(self)
        self.rooms = {}
        self.base_port = 40000
        self.room_count = 0

    def handle_accept(self):
        conn, addr = self.accept()
        print(conn)
        ChatSession(self, conn)


if __name__ == '__main__':
    s = ChatServer(6666)
    f = FileServer(6667)
    #a = Thread(target=asyncore.loop)
    #a.start()
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        print
def client_thread(buff):
	global BUFFER, count
	count += 1

	# just to show to bibhas sir-----
	ip_ob = IP.IP()
	my_ip = ip_ob.get_my_ip()
	#self.ip = my_ip
	#---------------------------------
	#my_ip = "10.0.0.4"         # ip of master
	conn = buff[0]
	self = buff[1]
	used_port = 0
	file_server = ""
	
	#infinite loop so that function do not terminate and thread do not end.
	#here should be added a try catch block - to detect lost connecions or failed connections
	try :
		while True:
			'''here there will be the logic 
				* to respond to interconnection request from another tier2 server (this will be constant connections)
				* the other type of connection may be from clients.. this can be search request, 
				* each client will be connected to the client
				* each upload or download will be done by server initiating a new connection from and to client respectively
			'''
			#Receiving from client
			data = conn.recv(BUFFER)
			print "data ",data
			print data[:-1]
			reply = 'OK...' + data


			# '7:' prefix for connection ... corresponding reply
			# '9:' search request ..   # inverted trie implementation
			# '15:' upload request from client
			if data[:-1] == '' :
				break
			elif data[:2] == '7:' :
				print 'New connection initiated; sending reply'
				message = '8:ACK'
				while  True:
					try :
						#Set the whole string
						conn.sendall(message)
					except socket.error:
						#Send failed
						print 'Send failed and retrying'
						continue
					finally :
						break
			elif data[:3] == '14:' :
				print 'Threaded implementation of file upload'
				used_port = self.PORT_Mapper.get_port()
				print "Get port = %d" %used_port
				self.PORT_Mapper.use_port(used_port)
				message = '15:port:' + str(used_port)
				file_server = FileServer.FileServer(used_port)
				file_server.setSharedDirectory('/home/kritika/Desktop/files')
				file_server.startServer()

				while  True:
					try :
						conn.sendall(message)
					except socket.error:
						print 'Send failed and retrying'
						break
					finally :
						break
						#break
			elif data[:3] == '16:' :
				#Threaded implementation of file upload
				print 'updation of trie after file upload'
				self.PORT_Mapper.free_port(used_port)
				message = '17:ACK:' + str("none")
				file_server.stopServer()
				filename = data[data.rfind(':')+1:]

				#update_trie(self, filename)


				masters_list = get_masters_from_persistence("server 2:LIST_OF_MASTERS")
				list_of_masters = masters_list.split()

				for master_ip in list_of_masters:
					update_trie(self, filename+'<IP>'+my_ip,master_ip)       # later not to store ip beacuse trie on master will just have the file names

				while  True:
					try :
						#Set the whole string
						conn.sendall(message)
					except socket.error:
						#Send failed
						print 'Send failed and retrying'
						continue
					finally :
						count -= 1
						conn.close()
						break
			#elif data[:3] == '10:' :   
			#	print 'Threaded implementation of file upload'
			#	message = '11:IP_address:10.0.0.4'
			#	while  True:
			#		try :
			#			#Set the whole string
			#			conn.sendall(message)
			#		except socket.error:
			#			#Send failed
			#			print 'Send failed and retrying'
			#			continue
			#		finally :
			#			break

			elif data[:-1] == 'exit':
				print 'connection closed' 
				conn.close()
				break
			#conn.sendall(reply)
	except :
		conn.close()
	finally :
		conn.close()
Beispiel #8
0
 def Submit(self):
     s = FileServer.Server(self.hostEd.text(),int(self.portEd.text()))
     s.Run()
Beispiel #9
0
 def start_file_server(self):
     self.file_server = FileServer.FileServer(self)
     self.ip_address = self.file_server.start_server()