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
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)
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()
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()
def _checkQuit(self,msg): if msg.strip() == clientproperties.CLIENT_SERVER_QUIT_MSG: print "[%s] %s" % (clientproperties._getTime(),clientproperties.CLIENT_QUIT_REQUEST_MSG) self._cleanUp()