module makes it easy for you to write your own clients and server ... and yesterday I produced "Hello World" style examples of each on the final day of our Python Programming Course
. I'm going to share these examples with you here ... but I'm also going to add a word of caution first to remind you that if you're programming with a well define protocol such as ssh, http, ntp, nntp, pop3, imap, smtp, snmp, rpc, dhcp, dns, etc, then you'll do far better to use the higher level classes that someone else has already written [http example]
. Unusually, the delegates yesterday required to write the protocol themselves.
TCP v UDP
You'll read that you can program sockets using TCP/IP or using UDP ... What's the difference?
Tcp is the most common; in Tcp, the packets are synchronized so that the receiving program will get them without data loss from the sender. So that's ideal for most data interchanges - you send a database backup or a web page over a network, and you want the client to get what has been served exactly.
By contract, Udp packets are sent asynchronously, and if the client doesn't receive them from the server, that's not regarded as a catastrophic failure; you don't want too many dropped packets, but a few is no problem. You might use Udp for a telephone conversation signal, where a click on the line is far better in the event of problems than the whole system lagging to await for a retransmission.
Put it another way - Tcp is connection oriented, with the transmitter verifying the receiver and Udp is connectionless - sending the data irrespective of whether it's received at the far end.
TCP - Transmission Control Protocol
UDP - User Datagram Protocol
Client v Server
There's not as much difference as you think!
The server sits waiting for a connection from any client, whereas the client specifies which server it's to connect into and "goes for it" ... but once they're connected, they chat back and forth very much in balance.
The server needs to stay running awaiting the next connection ... the client to close down and finish.
I have added comments into each of the following, and tested them too.
TCP/IP Server in Python
(test via telnet to the port)
TCP/IP Client in Python
(test via our server)
UDP Server in Python
(run this server ...)
UDP Client in Python
(... then talk to it via this client)
(written 2010-03-25, updated 2010-03-26)
Associated topics are indexed underY303 - Python Network Programming 
Python network programming - new FTP and socket level examples - (2013-05-14) 
Running operating system commands from your Python program - (2010-05-14) 
Multiple processes (forking) in Python - (2010-03-25) 
Python - fresh examples of all the fundamentals - (2009-08-20) 
Counting Words in Python via the web - (2009-08-18)A052 - Web Application Deployment - Networking - General 
Routers, Firewalls and multilayer servers - (2009-05-01) 
Routing Network Traffic - Proxies, Redirects and DNS - (2009-05-01) 
Our new .eu top level domain - (2006-06-19)P224 - Perl - Intersystem Communications 
Perl - doing several things at the same time - (2010-09-25) 
Different perl examples - some corners I rarely explore - (2010-07-18) 
Automated Browsing in Perl - (2009-09-11) 
Perl Socket Programming Examples - (2008-12-02) 
Heartbeat script in Perl - (2007-02-09) 
Perl - multiprocess applications - (2006-02-13)
Some other Articles
Lua tables - they are everythingRuth Davis, 1916 - 2010Email metrics and filteringGarlic bread without garlicTCP v UDP / Client v Server - Python examplesMethods that run on classes (static methods) in PythonFlexible search and replace in PythonNew brochures for the Melksham areaThe World Company Register - is it another scam?