I am working on a server application that receives data through a TCP socket in an XML format similar to XMPP, that is, each child element <root>essentially represents one separate request (stanza). The connection closes as soon as it is accepted </root>. I know that I should use a stream parser like SAX. Although, for convenience, I would prefer to have a tree-like interface for accessing each child element of stanza. (The data sent with each request is small, so I think it makes sense to read every stanza as a whole.)
What is the best way to implement this in Python (preferably v3)?
This is the code I would like to create. Feel free to point me in a completely different direction to solve this problem.
import socketserver
import settings
class MyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
class MyRequestHandler(socketserver.StreamRequestHandler):
def handle(self):
pass
if __name__ == '__main__':
server = MyServer((settings.host, settings.port), MyRequestHandler)
server.serve_forever()