1. Home
  2. Computing & Technology
  3. Python

Building a Web Client in Python

From Al Lukaszewski, for About.com

4 of 9

Giving Python the Internet Protocol Information

As I mentioned earlier, every network client needs to know the address of the machine, the port of the service, and the name of the file on which it is to operate. Theoretically, we could take the port number from the command line. However, because the port usually determines the service, it is safer to hardwire the port (and therefore the service) into the program. For a web service, we will look on port 80.

import port = 80

Next, let's take the server's address and the name of the file from the command line. Because we are working on the Web, we can make us of the DNS and allow for URLs.

host = sys.argv[1]
filename = sys.argv[2]

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Networking
  5. Programming Internet Protocols with Python : Giving Python the Internet Protocol Information

©2009 About.com, a part of The New York Times Company.

All rights reserved.