本文整理汇总了Python中Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verifyNum
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: setTile
def setTile(self,x, y, tile):
if x < 0 or y < 0 or x > self.width or y > self.height:
return
self.tiles[x+(y*self.width)] = tile.id
if gui.isMultiplayer:
Client.setTile(tile.id,x,y)
self.hasChanged = True
示例3: run
def run(self):
"""Main"""
global SON
global TLP
while not self._stopevent.isSet():
data = input(">")
if data == "quit":
TLP.stop()
self.stop()
elif data == "Tais toi!":
SON = False
elif data == "Parle!":
SON = True
elif re.search("je.*envoie.*fichier", data):
regex = re.search(r"[A-Za-z]*.\.[A-Za-z]*", data)
fileName = regex.group(0)
data2, infos = FileManager.sendFichier(0, fileName)
if infos[1] == 0:
Client.sendFile(data2, fileName)
else:
choix = input(data2)
data2, infos = FileManager.sendFichier(1, choix, infos)
elif len(data):
Client.sendMsg("T", str(data))
else:
continue
示例4: tick
def tick(self):
global x,y
super(Animal,self).tick()
xa = 0
ya = 0
self.centreX= self.x+31
self.centreY= self.y+63
xx = self.centreX >>5
yy = self.centreY >>5
if self.ticks%random.randint(1,100)==0:
xa = random.randint(-4,4)
else:
xa = 0
if xa != 0 or ya != 0:
self.isMoving = not self.move(xa, ya)
if Client.isHost == True and gui.isMultiplayer==True:
Client.moveEntity(self.id,self.x,self.y,self.movingDir,self.isSwimming)
else:
self.isMoving = False
if self.getTileUnder().getId() == Tile.water.getId():
self.isSwimming = True
else:
self.isSwimming = False
示例5: tick
def tick(self):
global x,y
super(Animal.Animal,self).tick()
self.breedCoolDown -=1
self.deathTimer -=1
if self.deathTimer <0:self.die()
self.centreX= self.x+16
self.centreY= self.y+16
xx = self.centreX >>5
yy = self.centreY >>5
if self.entityCollidedWith != None:
try:self.mate(self.level,self.entityCollidedWith)
except:print "That can't mate with a duck!"
#print self,self.entityCollidedWith
self.entityCollidedWith = None
if self.ticks%random.randint(1,500)==0:
self.xa = random.randint(-1,1)
self.ya = random.randint(-1,1)
if self.xa != 0 or self.ya != 0:
self.isMoving = not self.move(self.xa,self.ya)
if Client.isHost == True and gui.isMultiplayer == True:
Client.moveEntity(self.id,self.x,self.y,self.movingDir,self.isSwimming)
else:
self.isMoving = False
if self.getTileUnder().getId() == Tile.water.getId():
self.isSwimming = True
else:
self.isSwimming = False
示例6: init
def init(isclient, serverip, name, screen, clock):
screen.fill((0, 0, 0))
pygame.display.update()
if isclient:
try:
host, port = serverip.split(":")
except ValueError:
host = serverip
port = 12341
Client.connect(host)
Client.ready(name)
else:
try:
host, port = serverip.split(":")
except ValueError:
host = ""
port = 12341
Server = server()
while True:
if not isclient:
if Server.isdone():
break
for thing in Server.connected:
print(thing.name)
示例7: openList
def openList(self, root = None):
url = self.buildUrl()+self.itemsSubPath
if url[-1] == '/':
url = url[:-1]
self.server = self.getResource(url)
try:
self.entries, self.entryIds = self.server.zoa.items()
except xmlrpclib.Fault, error:
#print str(error)
# see if zoa object is installed
try:
Client.call('http://%s/zoa'%self.buildUrl(),
self.properties['username'], self.properties['passwd'],
function='version')
except Client.NotFound:
if wx.MessageBox(
'The zoa object not found in the root of your Zope tree.\n\n'
'Do you want to install it?', 'Install zoa',
wx.YES_NO | wx.ICON_QUESTION) == wx.YES:
import ZoaClient
conninfo = ('http://%s'%self.buildUrl(),
self.properties['username'], self.properties['passwd'])
ZoaClient.installFromFS(conninfo,
os.path.join(Preferences.pyPath, 'ZopeLib', 'zoa', ))
# try again, if this fails the real error should break thru
self.entries, self.entryIds = self.server.zoa.items()
else:
err = error.faultString
raise zopeHtmlErr2Strs(err)
示例8: tick
def tick(self):
super(Player,self).tick()
self.placeCooldown -=1
self.xa = 0
self.ya = 0
self.centreX= self.x+32
self.centreY= self.y+62
xx = self.centreX >>5
yy = self.centreY >>5
soundFXs = Sounds.Audio(False)
if Keyboard.keys['w']:
self.ya=-1
if Keyboard.keys['s']:
self.ya=1
if Keyboard.keys['a']:
self.xa=-1
if Keyboard.keys['d']:
self.xa=1
if self.xa != 0 or self.ya != 0:
self.isMoving = not self.move(self.xa, self.ya)
VRClient.move(self.x,self.y)
if gui.isMultiplayer == True:
Client.move(self.x,self.y,self.movingDir,self.isSwimming)
#soundFXs.Plysound(True,False,False,False,False)
else:
self.isMoving = False
soundFXs.Plysound(False,False,False,False,False)
if self.getTileUnder().getId() == Tile.water.getId()or self.getTileUnder().getId() == Tile.larva.getId() or self.getTileUnder().getId() == Tile.quicksand.getId():
self.isSwimming = True
else:
self.isSwimming = False
if self.getTileUnder().getId() == Tile.larva.getId()or self.getTileUnder().getId() == Tile.quicksand.getId():
if self.health < 0:
self.health = 0
self.health = self.health - 1
if self.health <= 0:
gui.gameOver = True
gui.defeat = True
if self.movingDir == 0:self.selectedTile=[xx,yy+1]#up
if self.movingDir == 1:self.selectedTile=[xx,yy-3]#down
if self.movingDir == 2:self.selectedTile=[xx-1,yy-1]#left
if self.movingDir == 3:self.selectedTile=[xx+1,yy-1]#right
if self.selectedTile[0]<<5 != self.inHand.x or self.selectedTile[1]<<5!=self.inHand.y:
self.inHand.x = self.selectedTile[0]<<5
self.inHand.y = self.selectedTile[1]<<5
self.inHand.CanPlace()
else:
self.inHand.x = self.selectedTile[0]<<5
self.inHand.y = self.selectedTile[1]<<5
if Keyboard.keys['e'] and self.placeCooldown <0:
if self.inHand.placeInLevel():self.placeCooldown = 20
示例9: PyChatGUI
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()
示例10: start
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)
示例11: loadLevelFromFile
def loadLevelFromFile(self,path):
if Client.isHost == True and gui.isMultiplayer==True:
self.addTiles(path)
Client.sendTiles(self.tiles)
elif gui.isMultiplayer==True:
while len(self.tiles)<2:#wait for tiles from host
#print "Waiting for tiles.."
pass
else:
self.addTiles(path)
示例12: __init__
def __init__(self,level, x, y):
super(Animal,self).__init__(level,x,y)
self.x = x
self.y = y
self.id = len(level.entities)
self.isSwimming = False
self.isMoving = False
self.img = pygame.image.load("animals/crab.png")
self.basicFont = pygame.font.SysFont(None, 32)
if Client.isHost == True:
Client.sendEntity("Crab",x,y)
示例13: __init__
def __init__(self, ip_addr, port):
self.TCPsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.TCPsock.bind((ip_addr, port))
self.node_list = []
self.clients = []
#self.connectedList =[]
self.TCPsock.listen(1)
conn, addr = self.TCPsock.accept()
print "server accepted connection from ..\n"
data_string = conn.recv(1024)
data = pickle.loads(data_string)
self.node_list = data
print "printing list: \n"
for x in self.node_list:
print "ip:"
print x.ip_addr
print "\t"
print "Port:"
print x.port
print "\n"
i = 0
for x in self.node_list:
if (x.port == port) :
continue
#c = Client.client(x.ip_addr, x.port, self.connectedList)
c = Client.client(x.ip_addr, x.port)
self.clients.append(c)
self.clients[i].start()
i = i + 1
示例14: __init__
def __init__(self, linklayer, transportlayer, config, stage2 = "", duckencoder = None):
# state value to inform sub threads of running state
self.running = False
self.stage2=stage2
self.config = config
self.client = Client() # object to monitor state of remote client
self.client.registerCallbackOnConnectChange(self.onClientConnectStateChange)
#self.control_sysinfo_response = BlockingQueue("CONTROL_SERVER_SYSINFO_RESPONSE")
self.server_thread_in = Thread(target = self.__input_handler, name = "P4wnP1 Server Input Loop", args = ( ))
self.server_thread_out = Thread(target = self.__output_handler, name = "P4wnP1 Server Output Loop", args = ( ))
self._next_client_method_id = 1
self.tl = transportlayer
self.ll = linklayer
self.__pending_server_methods = {}
self.duckencoder = duckencoder
self.mousescriptparser = MouseScriptParser()
# register Listener for LinkLayer signals to upper layers (to receive LinkLayer connection events)
dispatcher.connect(self.signal_handler_transport_layer, sender="TransportLayerUp")
self.client_connected_commands = ["ls", "pwd", "cd", "shell", "CreateProc", "interact", "download", "upload", "echotest", "GetClientProcs", "KillClient", "KillProc"]
self.setPrompt(False, False)
cmd.Cmd.__init__(self)
self.intro = '''=================================
示例15: __init__
def __init__(self, host, port, name, manual):
self.client = Client(host, port, name, manual)
pygame.init()
# the GUI should reference the client, but never modify it
# self.bg = pygame.image.load(os.path.join('data', 'map.png'))
self.screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Warlords")
pygame.mouse.set_visible(1)
# make icon invisible
icon = pygame.Surface((1, 1))
icon.set_alpha(0)
pygame.display.set_icon(icon)
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont(None, 16)
self.font2 = pygame.font.SysFont(None, 64)
self.font3 = pygame.font.SysFont(None, 32)
self.chatTextBox = Input(x=5, y=460, font=self.font, maxlength=63, color=(0, 0, 0), prompt="Chat: ")
self.playTextBox = Input(x=210, y=400, font=self.font3, maxlength=20, color=(255, 0, 0), prompt="Input Play: ")
self.swapTextBox = Input(
x=210, y=430, font=self.font3, maxlength=2, color=(255, 0, 0), prompt="Input Card to Swap: "
)