Find us on Google+ Kill the code: How to create a python server ?

Friday 27 July 2012

How to create a python server ?

Initially,you must have Python installed.

After the installation,do following.

Open a notepad file and type the following code there:

from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer((”, port), CGIHTTPRequestHandler)
print(“Starting simple_httpd on port: ” + str(httpd.server_port))
httpd.serve_forever()

Save it and remember the location of it.

Thereby,

For Windows user

1.Go to Start –>All Programs–>Python 3.2–>IDLE
2.Press Ctrl+O to open the file saved above.
3.Press F5.



Above window with message “Staring simple_httpd on port 8080″ shows success of our work.

For Unix And Mac OS X Users

You need to do two things to prepare your CGI script for execution:

1. Set the executable bit for your CGI using the chmod +x command.
2. Add the following line of code to the very top of your program:
#! /usr/local/bin/python3

Thereby do another thing:
1. Open Terminal (or Shell).
2. Type python

That’s it,server is running on your *NIX OS.

That’s all how a simple “home-made” Python server is made and run,simply with above 4 steps.Send your queries below in the comments.

No comments:

Post a Comment