if we include comments and blank linesas we'll see later in this bookit' also easy to build proprietary network servers with low-level socket calls in pythonbut the standard library provides canned implementations for many common server typesweb based or otherwise the socketserver modulefor instancesupports threaded and forking versions of tcp and udp servers third-party systems such as twisted provide even more implementations for serving up web contentthe standard library modules used in example - provide what we need example - pp \preview\webserver py ""implement an http web server in python that knows how to run server-side cgi scripts coded in pythonserves files and scripts from current working dirpython scripts must be stored in webdir\cgi-bin or webdir\htbin""import ossys from http server import httpservercgihttprequesthandler webdir port where your html files and cgi-bin script directory live default os chdir(webdirrun in html root dir srvraddr (""portmy hostnameportnumber srvrobj httpserver(srvraddrcgihttprequesthandlersrvrobj serve_forever(run as perpetual daemon the classes this script uses assume that the html files to be served up reside in the current working directory and that the cgi scripts to be run live in cgi-bin or htbin subdirectory there we're using cgi-bin subdirectory for scriptsas suggested by the filename of example - some web servers look at filename extensions to detect cgi scriptsour script uses this subdirectory-based scheme instead to launch the serversimply run this script (in console windowby an icon clickor otherwise)it runs perpetuallywaiting for requests to be submitted from browsers and other clients the server listens for requests on the machine on which it runs and on the standard http port number to use this script to serve up other websiteseither launch it from the directory that contains your html files and cgi-bin subdirectory that contains your cgi scriptsor change its webdir variable to reflect the site' root directory (it will automatically change to that directory and serve files located therebut where in cyberspace do you actually run the server scriptif you look closely enoughyou'll notice that the server name in the addresses of the prior section' examples (near the top right of the browser after the this simplei am running the web server on the same machine as the web browserthat' what the server name "localhost(and the equivalent ip address "means that isthe client and server machines are the samethe client (web browser sneak preview