before we see these programs in actionlet' take minute to explain how this client and server do their stuff both are fairly simple examples of socket scriptsbut they illustrate the common call patterns of most socket-based programs in factthis is boilerplate codemost connected socket programs generally make the same socket calls that our two scripts doso let' step through the important points of these scripts line by line programs such as example - that provide services for other programs with sockets generally start out by following this sequence of callssockobj socket(af_inetsock_streamuses the python socket module to create tcp socket object the names af_inet and sock_stream are preassigned variables defined by and imported from the socket moduleusing them in combination means "create tcp/ip socket,the standard communication device for the internet more specificallyaf_inet means the ip address protocoland sock_stream means the tcp transfer protocol the af_inet/sock_stream combination is the default because it is so commonbut it' typical to make this explicit if you use other names in this callyou can instead create things like udp connectionless sockets (use sock_dgram secondand unix domain sockets on the local machine (use af_unix first)but we won' do so in this book see the python library manual for details on these and other socket module options using other socket types is mostly matter of using different forms of boilerplate code sockobj bind((myhostmyport)associates the socket object with an address--for ip addresseswe pass server machine name and port number on that machine this is where the server identifies the machine and port associated with the socket in server programsthe hostname is typically an empty string ("")which means the machine that the script runs on (formallyall available local and remote interfaces on the machine)and the port is number outside the range to (which is reserved for standard protocolsdescribed earliernote that each unique socket dialog you support must have its own port numberif you try to open socket on port already in usepython will raise an exception also notice the nested parentheses in this call--for the af_inet address protocol socket herewe pass the host/port socket address to bind as two-item tuple object (pass string for af_unixtechnicallybind takes tuple of values appropriate for the type of socket created sockobj listen( starts listening for incoming client connections and allows for backlog of up to five pending requests the value passed sets the number of incoming client requests queued by the operating system before new requests are denied (which happens only if server isn' fast enough to process requests before the queues fill upa network scripting