本文整理汇总了Python中Client.start方法的典型用法代码示例。如果您正苦于以下问题:Python Client.start方法的具体用法?Python Client.start怎么用?Python Client.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client
的用法示例。
在下文中一共展示了Client.start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verifyNum
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
def verifyNum():
try:
errorlabel.place_forget()
key = decompress(fiveDigit.get())
'''if len(key) != 5: #MUST BE FIVE # Supported @ compression
raise TypeError
key = int(key)
hostname = unencrypt(key)'''
try:
global conObject
conObject = Client(key) #key and onDisconnect
conObject.favdir = favdir
conObject.PROGCLASS = ProgHandler
#c.onDisconnect = handleDC
conObject.start()
#c.onProgress = updateProgress;
except Exception as ex:
pr("Couldn't start client: "+str(ex))
errorlabel.config(text="The number \""+fiveDigit.get()+"\"\n is not a valid host!")
errorlabel.place(relx="0.0",rely="0.3")
else:
numFrame.place_forget()
dropLabel.place(relx="0.05",rely="0.27") # PUT THIS THERE WHEN CONNECTED
except ValueError: #(ValueError,TypeError):
errorlabel.config(text="The input \""+fiveDigit.get()
+"\"\nis not a five digit number.")
errorlabel.place(relx="0.0",rely="0.3")
示例2: PyChatGUI
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
class PyChatGUI(QDialog, Ui_Dialog):
send_message_signal = pyqtSignal(str)
def __init__(self, parent=None, socket_=None, ip=None):
QDialog.__init__(self)
# try:
if not socket_:
print ip
self.socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket_.connect((ip, 9000))
else:
self.socket_ = socket_
#Set up the client thread
self.client = Client(self, self.socket_)
self.client.receive_message_signal.connect(self.receive_message)
self.client.start()
self.parent = parent
self.parent.trayIcon.messageClicked.connect(self.showDialog)
self.setupUi(self)
self.setVisible(True)
self.sendButton.clicked.connect(self.send_message)
def showDialog(self):
self.setVisible(True)
def sendMessage(self):
"""Emit the message to be sent over the network"""
self.textBrowser.append('me: ' + self.lineEdit.text())
self.send_message_signal.emit(self.lineEdit.text())
self.lineEdit.setText('')
self.lineEdit.setFocus()
def receiveMessage(self, msg):
"""Append the message to the current dialog window"""
try:
name = self.parent.get_connected_pc_name(self.socket_)
except Exception as e:
print e
print 'Closing sockets...'
self.socket_.close()
self.parent.server.close()
return
if not self.isVisible():
self.parent.trayIcon.showMessage('New message', 'You have a new message from ' + name)
self.textBrowser.append(name + ': ' + unicode(msg))
self.lineEdit.setText('')
self.lineEdit.setFocus()
def closeEvent(self, event):
self.setVisible(False)
self.socket_.close()
event.ignore()
示例3: start
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
def start(self):
try:
ss = socket(AF_INET,SOCK_STREAM)
ss.bind(('',9082))
ss.listen(1000)
while True:
connection,address = ss.accept()
clientInstance = Client(attachingChatServer=self,connSocket=connection,lock=self.lock)
clientInstance.start()
except IOError,(errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
示例4:
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
# Insert your key here
c.KEY = "g2lVRjJN96svcwTYPG8K0MmUfdQq6Xg1"
# Tell the client to use this function to decide the next move.
# This function is defined above.
c.decide_move = dummy
# Connect to the game server
if c.connect():
# If we successfully connected, start playing
print 'Connected'
# Tell the client to start listening for maps
c.start()
# Wait until the user presses a key
raw_input('Press any key to quit...')
# Tell the client to stop listening for maps
c.stop()
# Wait for the client to finish its last request
c.join()
# Disconnect from the server
c.disconnect()
else:
# If we didn't successfully connected, exit
print 'Could not connect'
示例5: PyChatClient
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
class PyChatClient(QMainWindow, Ui_ChatWindow):
sendSignal = pyqtSignal(str)
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setupUi(self)
# self.clients = []
if sys.platform == 'darwin':
self.menubar.setNativeMenuBar(False)
# self.pc_names = {}
# self.pc_names['localhost'] = 'Randy'
self.server = Server(self)
self.server.message.connect(self.receiveMessage)
self.server.start()
self.createActions()
self.createTrayIcon()
self.sendButton.clicked.connect(self.send_message)
self.lineEdit.returnPressed.connect(self.send_message)
self.actionQuit.triggered.connect(qApp.quit)
self.trayIcon.setIcon(QIcon(':images/trash.svg'))
self.trayIcon.show()
def showDialog(self):
ip_address = socket.gethostbyname('CTCDCSVYQ1.CCPS.WAN')
#ip_address = socket.gethostbyname('localhost')
self.gui = PyChatGUI(parent=self, socket_=None, ip=ip_address)
def receiveMessage(self, socket_):
PyChatGUI(self, socket_)
def connectToServer(self):
self.client = Client(self)
self.client.start()
self.sendSignal.connect(self.client.send_message)
self.client.message.connect(self.receiveMessage)
def sendMessage(self):
self.textBrowser.append(self.lineEdit.text())
self.sendSignal.emit(self.lineEdit.text())
self.lineEdit.setText('')
self.lineEdit.setFocus()
def getConnectedPcName(self, socket_):
return 'Mr. Valis'
def createActions(self):
self.connectAction = QAction("&Send Message", self,
triggered=self.showDialog)
self.quitAction = QAction("&Quit", self,
triggered=self.quit)
def addPCActions(self):
'''To be overridden in a child class'''
pass
def quit(self):
self.server.close()
qApp.quit()
def createTrayIcon(self):
self.trayIconMenu = QMenu(self)
self.trayIconMenu.addAction(self.connectAction)
self.addPCActions()
self.trayIconMenu.addSeparator()
self.trayIconMenu.addAction(self.quitAction)
self.trayIcon = QSystemTrayIcon(self)
self.trayIcon.setContextMenu(self.trayIconMenu)
def setVisible(self, visible):
self.connectAction.setEnabled(self.isMaximized() or not visible)
super(PyChatClient, self).setVisible(visible)
def closeEvent(self, event):
if self.trayIcon.isVisible():
QMessageBox.information(self, "Systray",
"The program will keep running in the system tray. To "
"terminate the program, choose <b>Quit</b> in the "
"context menu of the system tray entry.")
# self.hide()
# self.client.running = False
event.ignore()
示例6: PyChat
# 需要导入模块: import Client [as 别名]
# 或者: from Client import start [as 别名]
class PyChat(QMainWindow, Ui_ChatWindow):
sendSignal = pyqtSignal(str)
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.clients = []
if sys.platform == 'darwin':
self.menubar.setNativeMenuBar(False)
self.server = Server(self)
self.server.message.connect(self.receiveMessage)
self.server.start()
self.createActions()
self.createTrayIcon()
self.sendButton.clicked.connect(self.send_message)
self.lineEdit.returnPressed.connect(self.send_message)
self.actionQuit.triggered.connect(qApp.quit)
self.trayIcon.setIcon(QIcon(':images/trash.svg'))
self.trayIcon.show()
def showDialog(self):
action = self.sender()
host = self.actions[action]
ip_address = socket.gethostbyname(host + '.CCPS.WAN')
self.gui = PyChatGUI(parent=self, socket_=None, ip=ip_address)
def receiveMessage(self, msg):
PyChatGUI(self, msg)
def connectToServer(self):
self.client = Client(self)
self.client.start()
self.sendSignal.connect(self.client.send_message)
self.client.message.connect(self.receiveMessage)
def send_message(self):
self.textBrowser.append(self.lineEdit.text())
self.sendSignal.emit(self.lineEdit.text())
self.lineEdit.setText('')
self.lineEdit.setFocus()
def createActions(self):
self.connectAction = QAction("&Send Message", self,
triggered=self.showDialog)
self.quitAction = QAction("&Quit", self,
triggered=qApp.quit)
self.createMoreActions()
def createMoreActions(self):
self.actions = {}
for line in open('PCs.txt'):
name, ip_address = line.split(';')
action = QAction(name, self,
triggered=self.showDialog)
self.actions[action] = ip_address.strip()
def createTrayIcon(self):
self.trayIconMenu = QMenu(self)
self.trayIconMenu.addAction(self.connectAction)
for action in self.actions:
self.trayIconMenu.addAction(action)
self.trayIconMenu.addSeparator()
self.trayIconMenu.addAction(self.quitAction)
self.trayIcon = QSystemTrayIcon(self)
self.trayIcon.setContextMenu(self.trayIconMenu)
def setVisible(self, visible):
self.connectAction.setEnabled(self.isMaximized() or not visible)
super(PyChat, self).setVisible(visible)
def closeEvent(self, event):
if self.trayIcon.isVisible():
QMessageBox.information(self, "Systray",
"The program will keep running in the system tray. To "
"terminate the program, choose <b>Quit</b> in the "
"context menu of the system tray entry.")
# self.hide()
# self.client.running = False
event.ignore()