Итак, я работаю над iPhone-приложением, которое требует, чтобы сокет обрабатывал несколько клиентов для онлайн-игр. Я пробовал Twisted, и с большим трудом мне не удалось получить кучу информации, которую нужно отправить сразу, поэтому я теперь собираюсь попробовать сокет.
Мой вопрос заключается в следующем: как бы вы могли подключить несколько клиентов? Я пробовал списки, но я просто не могу понять формат для этого. Как это можно сделать, когда сразу несколько клиентов подключены, и я могу отправить сообщение конкретному клиенту?
Спасибо!
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 50000 # Reserve a port for your service.
print 'Server started!'
print 'Waiting for clients...'
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
while True:
msg = c.recv(1024)
print addr, ' >> ', msg
msg = raw_input('SERVER >> ')
c.send(msg);
#c.close() # Close the connection