15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The teller is, of course, the server that runs in an infinite loop. Each customer is a client with a need that<br />

requires servicing. Customers arrive and are serviced by the teller in a first-come-first-served manner.<br />

Once a transaction has been completed, the client goes away while the server either serves the next<br />

customer or sits and waits until one comes along.<br />

Why is all this important? The reason is that this style of execution is how client/server architecture<br />

works in a general sense. Now that you have the basic idea, let us adapt it to network programming,<br />

which follows the software client/ server architecture model.<br />

16.1.2. Client/Server Network <strong>Programming</strong><br />

Before any servicing can be accomplished, a server must perform some preliminary setup procedures to<br />

prepare for the work that lies ahead. A communication endpoint is created which allows a server to<br />

"listen" for requests. One can liken our server to a company receptionist or switchboard operator who<br />

answers calls on the main corporate line. Once the phone number and equipment are installed and the<br />

operator arrives, the service can begin.<br />

This process is the same in the networked worldonce a communication endpoint has been established,<br />

our listening server can now enter its infinite loop to wait for clients to connect and be serviced. Of<br />

course, we must not forget to put that phone number on company letterhead, in advertisements, or<br />

some sort of press release; otherwise, no one will ever call!<br />

On a related note, potential clients must be made aware that this server exists to handle their<br />

needsotherwise, the server will never get a single request. Imagine creating a brand new Web site. It<br />

may be the most super-duper, awesome, amazing, useful, and coolest Web site of all, but if the Web<br />

address or Uniform Resource Locator (URL) is never broadcast or advertised in any way, no one will ever<br />

know about it, and it will never see the light of day. The same thing applies for the new telephone<br />

number of corporate headquarters. No calls will ever be received if the number is not made known to<br />

the public.<br />

Now you have a good idea as to how the server works. You have gotten past the difficult part. The client<br />

side stuff is much more simple than on the server side. All the client has to do is to create its single<br />

communication endpoint, establish a connection to the server. The client can now make a request, which

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!