estoy tratando de ejecutar un servidor trenzado con pygame-clientes:Clientes retorcidos dentro de 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...
Y aquí es el servidor:
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()
estoy corriendo este servidor con el código de cliente con el reactor.CallLater() método y código pygames y el cliente se conecta bien. ¿Estoy usando incorrectamente el método del reactor o hay algo estructuralmente incorrecto con el código pygames? Cualquier ayuda sería apreciada.
Así que no sé si el bucle dentro de los pygames mordió nunca rompe a llamar el reactor de nuevo?
es algo no funciona? ¿Dónde está tu problema? – sloth
Voy a editar para explicar más a fondo. – tijko