所以我正在开发一款iPhone应用程序,它需要一个套接字来处理多个客户端以进行在线游戏.我已经尝试过Twisted,并且付出了很多努力,我没有立即获得一堆信息,这就是为什么我现在要尝试socket.
我的问题是,使用下面的代码,您将如何连接多个客户端?我已经尝试了列表,但我无法弄清楚它的格式.如何在一次连接多个客户端并且能够向特定客户端发送消息的情况下实现这一目标?
谢谢!
#!/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 = …Run Code Online (Sandbox Code Playgroud)