示例#1
0
	def _cleanUp(self):
		print "[%s] %s" % (clientproperties._getTime(),clientproperties.CLIENT_CLEANUP_MSG)
		if self.m_sock is not None:
			try:
				self.m_sock.shutdown(2)
				self.m_sock.close()
			except:
				print "[%s] %s" % (clientproperties._getTime(),clientproperties.CLIENT_ERR_CLOSING_SOCK)
		self.m_die = True
示例#2
0
	def connect(self):
		try:
			self.m_sock.connect(self.m_servAddr)
			print "[%s] %s %s" % (clientproperties._getTime(),clientproperties.CLIENT_CONNECTED_MSG,self.m_servAddr)
			self.start()
		except:
			print "[%s] %s %s" % (clientproperties._getTime(),clientproperties.CLIENT_CANNOT_CONNECT_MSG,self.m_servAddr)
			self._cleanUp()
			sys.exit(2)
示例#3
0
	def start(self):
		while not self.m_die:			
			msg = self._recv()			
			self._checkQuit(msg)
			print "[%s] %s: %s" % (clientproperties._getTime(),clientproperties.SERVER,msg)

			#display menu
			if not self.m_die:
				showMenu()
				self._handleInput()
示例#4
0
	def _handleInput(self):
		try:
			msg = raw_input()
			
			while(not self._correctResponse(msg)):
				print clientproperties.CLIENT_CHOICE_INVALID
				msg = raw_input()

			self._sendChoiceToServer(msg)
		except KeyboardInterrupt:
			print "[%s] %s" % (clientproperties._getTime(),clientproperties.CLIENT_INTERRUPT_EXITING_MSG)
			self._cleanUp()
示例#5
0
	def _checkQuit(self,msg):
		if msg.strip() == clientproperties.CLIENT_SERVER_QUIT_MSG:
			print "[%s] %s" % (clientproperties._getTime(),clientproperties.CLIENT_QUIT_REQUEST_MSG)	
			self._cleanUp()