そのため、オンライン ゲーム用に複数のクライアントを処理するためにソケットを必要とする 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