저는 간단한 소켓 서버를 작성 중이며 클라이언트 상태 (인증 및 물건)를 추적하고자합니다. handle_read()가 호출 될 때마다 나는 그 특정 클라이언트에 대해 아무것도 모른다. 고객 ID 등을 알면 도움이 될 것입니다. 여기에 지금까지이 작업은 다음과 같습니다파이썬 asyncore는 클라이언트를 추적합니다.
import asyncore
import socket
class EchoHandler(asyncore.dispatcher_with_send):
def handle_read(self):
data = self.recv(8192)
self.send(data)
class EchoServer(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((host, port))
self.listen(5)
def handle_accept(self):
pair = self.accept()
if pair is None:
pass
else:
sock, addr = pair
print 'Incoming connection from %s' % repr(addr)
handler = EchoHandler(sock)
server = EchoServer('localhost', 8080)
asyncore.loop()
정확하게 필요한 것, 감사합니다! –