मैं pygame-ग्राहकों के साथ एक मुड़-सर्वर को चलाने के लिए कोशिश कर रहा हूँ:ट्विस्ट क्लाइंट pygame mainloop के भीतर?
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()
मैं बाहर के साथ ग्राहक कोड के साथ इस सर्वर चल रहा हूँ:
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...
और यहाँ सर्वर है रिएक्टर। कॉलरेटर() विधि और पायग्स कोड और क्लाइंट ठीक से जुड़ता है। क्या मैं रिएक्टर विधि गलत का उपयोग कर रहा हूं या क्या pygames कोड के साथ कुछ संरचनात्मक रूप से गलत है? किसी भी सहायता की सराहना की जाएगी।
तो मुझे नहीं पता कि pygames बिट के अंदर लूप कभी रिएक्टर को फिर से कॉल करने के लिए टूट जाता है या नहीं?
क्या कुछ काम नहीं कर रहा है? आपकी समस्या कहां है? – sloth
मैं अधिक से अधिक व्याख्या करने के लिए संपादित कर दूंगा। – tijko