Sto cercando di eseguire un twisted-server con pygame-clienti:Client contorti all'interno di pygame mainloop?
class ChatClientProtocol(LineReceiver):
def lineReceived(self,line):
print (line)
class ChatClient(ClientFactory):
def __init__(self):
self.protocol = ChatClientProtocol
def main():
flag = 0
default_screen()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
return
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
# some rect.collidepoint(pos) rest of loop...
E qui è il server:
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
class Chat(LineReceiver):
def __init__(self, users, players):
self.users = users
self.name = None
self.players = players
def connectionMade(self):
new = 'player_' + str(len(self.players) + 1)
self.players.append(new)
self.sendLine(str(self.players,))
class ChatFactory(Factory):
def __init__(self):
self.users = {} #maps instances to clients
self.players = []
def buildProtocol(self, addr):
return Chat(self.users,self.players)
reactor.listenTCP(6000, ChatFactory())
reactor.run()
Io corro questo server con il codice del client con il reactor.CallLater() metodo e codice pygames e il client si connette bene. Sto usando il metodo del reattore sbagliato o c'è qualcosa di strutturalmente sbagliato nel codice pygames? Qualsiasi aiuto sarebbe apprezzato.
Quindi non so se il loop all'interno del bit pygames si rompa mai per chiamare di nuovo il reattore?
Qualcosa non funziona? Dov'è il tuo problema? – sloth
Mi aggiornerò per spiegare più chiaramente. – tijko