I'm trying to run a twisted-server with pygame-clients:
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... And here is the 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() I'm running this server with the client code with out the reactor.CallLater() method and pygames code and the client connects fine. Am I using the reactor method wrong or is there something structurally wrong with the pygames code? Any help would be appreciated.
So I don't know if the loop within the pygames bit ever breaks to call the reactor again?