Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User catch's Avatar
    Join Date
    Nov 2008
    Posts
    24
    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:

    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()
    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.

    Your aid would greatly be appreciated.

    Thanks, in advance.

  2. #2
    Regular Contributor aya42's Avatar
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125
    Quote Originally Posted by catch View Post
    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.
    If your 'local machine' runs a Unix-like OS (e.g. Linux, MacOSX), then only the 'root' user may bind a socket to a port number less than 1024.

    Also note that the BaseHTTPServer class is not capable of handling multiple requests simultaneously, so you might be better off using apache with mod_python.

  3. #3
    Registered User catch's Avatar
    Join Date
    Nov 2008
    Posts
    24
    @aya42: I have tested it running freely under the root account. It is running very good =)

    And, I seem to notice that BaseHTTPServer is limited in listening to the number of requests but this fine for now. However, I'm using and will be sticking with nginx, instead of Apache, as my web server. But your suggestions are most welcome. There's still a big room for improvement for me.

    Cheers and Happy Easter!

Similar Threads

  1. Accessing Infrared port using J2ME
    By gurpreets in forum General Development Questions
    Replies: 4
    Last Post: 2009-01-30, 18:58
  2. Accessing Infrared port using J2ME
    By gurpreets in forum Mobile Java General
    Replies: 1
    Last Post: 2005-08-23, 16:32
  3. Accessing Infrared port using J2ME
    By gurpreets in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2005-08-22, 11:54
  4. Accessing Infrared port using J2ME
    By gurpreets in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-08-22, 11:49
  5. accessing pop port
    By sockncoke in forum Symbian C++
    Replies: 1
    Last Post: 2004-07-02, 05:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved