Hello again everyone,
I've just started developing my first PyS60 app. Things have been running good since I have started reading Scheible's book.
Anyway, going to my problem... I have used Scheible's web server code as a first step to a mature server and here it is:
I ran the code on a local machine and changed the listening port to 80 instead of 9000. I wanted my server to listen and ONLY listen to port 80. However, things didn't work out well. I've got a permission denied on the terminal. Is there a magic to this? With this step, I will be communicating my mobile phone to this server, if this would matter.Code:import BaseHTTPServer, SimpleHTTPServer, cgi, traceback, json class Server(BaseHTTPServer.HTTPServer): allow_reuse_address = True class Handler(SimpleHTTPServer. SimpleHTTPRequestHandler): def do_POST(self): try: size = int(self.headers["Content-length"]) msg = json.read(self.rfile.read(size)) reply = process_json(msg) except: self.send_response(500) self.end_headers() print "Function process_json failed:" traceback.print_exc() return self.send_response(200) self.end_headers() self.wfile.write(json.write(reply)) def do_GET(self): if '?' in self.path: path, query_str = self.path.split("?", 1) query = cgi.parse_qs(query_str) else: path = self.path query = {} try: mime, reply = process_get(path, query) except: self.send_response(500) self.end_headers() print >> self.wfile, "Function process_query failed:\n" traceback.print_exc(file=self.wfile) return self.send_response(200) self.send_header("mime-type", mime) self.end_headers() self.wfile.write(reply) def process_json(msg): return msg def process_get(path, query): return "text/plain", "Echo: path '%s' and query '%s'" %\ (path, query) def init_server(): print "Server starts..." init_server() httpd = Server(('', 80), Handler) httpd.serve_forever()
Your aid would greatly be appreciated.
Thanks, in advance.

Reply With Quote


