Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
TCP v UDP / Client v Server - Python examples

Python's socket 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.

Samples

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 as below, or enter http://melksh.am/nnnn for individual articles
Y303 - Python Network Programming
  [2365] Counting Words in Python via the web - (2009-08-18)
  [2368] Python - fresh examples of all the fundamentals - (2009-08-20)
  [2694] Multiple processes (forking) in Python - (2010-03-25)
  [2765] Running operating system commands from your Python program - (2010-05-14)
  [4087] Python network programming - new FTP and socket level examples - (2013-05-14)

P224 - Perl - Intersystem Communications
  [604] Perl - multiprocess applications - (2006-02-13)
  [1073] Heartbeat script in Perl - (2007-02-09)
  [1918] Perl Socket Programming Examples - (2008-12-02)
  [2402] Automated Browsing in Perl - (2009-09-11)
  [2876] Different perl examples - some corners I rarely explore - (2010-07-18)
  [2970] Perl - doing several things at the same time - (2010-09-25)

A052 - Web Application Deployment - Networking - General
  [768] Our new .eu top level domain - (2006-06-19)
  [2149] Routing Network Traffic - Proxies, Redirects and DNS - (2009-05-01)
  [2150] Routers, Firewalls and multilayer servers - (2009-05-01)


Back to
Multiple processes (forking) in Python
Previous and next
or
Horse's mouth home
Forward to
Garlic bread without garlic
Some other Articles
Lua tables - they are everything
Ruth Davis, 1916 - 2010
Email metrics and filtering
Garlic bread without garlic
TCP v UDP / Client v Server - Python examples
Methods that run on classes (static methods) in Python
Flexible search and replace in Python
New brochures for the Melksham area
The World Company Register - is it another scam?
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2695_TCP ... mples.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb