I want to store all the messages from clients in a list on my 'TCP server'.
import SocketServer
class MainServerHandler(SocketServer.BaseRequestHandler):
requests = []
def handle(self):
message = self.request.recv(4)
self.requests.append(message)
HOST, PORT = "localhost", 9999
server = SocketServer.TCPServer((HOST, PORT), MainServerHandler)
server.serve_forever()
When server receives the first message, the handle function appends the message to list.
When server receives the second message from client, there is no trace of the previously appended message.
DISCLAIMER : I know why this is happening. I am just not able to figure out a way to store all the messages in a list. I only want to use
SocketServer
to implement this.