Ben pygame-müşterilerle bükülü sunucu yönetmeye çalışıyorum:Pygame mainloop içindeki Twisted istemcileri?
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()
dışarı ile müşteri kodu ile bu sunucu çalıştırıyorum: Burada
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...
Ve sunucusudur reactor.CallLater() yöntemi ve pygames kodu ve istemci iyi bağlanır. Reaktör yöntemini yanlış mı kullanıyorum yoksa pygames koduyla yapısal olarak yanlış bir şey mi var? Herhangi bir yardım takdir edilecektir.
Bu yüzden, pygames bitindeki döngü, reaktörü tekrar aramak için kırılıp kırılmadığını bilmiyor muyum?
Bir şey çalışmıyor mu? Senin sorunun nerede? – sloth
Daha fazla açıklamak için düzenleyeceğim. – tijko