Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Programming Linux sockets, Part 2: Using UDP

Writing UDP sockets applications in C and in Python

David Mertz (, Developer, Gnosis Software
David Mertz
David Mertz has been writing the developerWorks columns Charming Python and XML Matters since 2000. Check out his book Text Processing in Python. For more on David, see his personal Web page.

Summary:  This intermediate-level tutorial extends the basics covered in Part 1 on programming using sockets. Part 2 focuses on the User Datagram Protocol (UDP) and demonstrates how to write UDP sockets applications in C and in Python. Although the code examples in this tutorial are in Python and C, they translate well to other languages.

View more content in this series

Date:  25 Jan 2004
Level:  Introductory PDF:  A4 and Letter (300 KB | 19 pages)Get Adobe® Reader®

Activity:  50908 views

Before you start

About this tutorial

IP sockets are the lowest-level layer upon which high-level Internet protocols are built: everything from HTTP to SSL to POP3 to Kerberos to UDP-Time. To implement custom protocols, or to customize implementation of well-known protocols, a programmer needs a working knowledge of the basic socket infrastructure. A similar API is available in many languages; this tutorial uses C programming as a ubiquitous low-level language, and Python as a representative higher-level language for examples.

In Part 1 of this tutorial series, David introduced readers to the basics of programming custom network tools using the widespread and cross-platform Berkeley Sockets Interface. In this tutorial, he picks up with further explanation of User Datagram Protocol (UDP), and continues with a discussion of writing scalable socket servers.


This tutorial is best suited for readers with at least a basic knowledge of C and Python. However, readers who are not familiar with either programming language should be able to make it through with a bit of extra effort; most of the underlying concepts will apply equally to other programming languages, and calls will be quite similar in most high-level scripting languages like Ruby, Perl, TCL, etc.

Although this tutorial introduces the basic concepts behind IP (Internet Protocol) networks, some prior acquaintance with the concept of network protocols and layers will be helpful (see the Resources at the end of this tutorial for background documents).

1 of 9 | Next


TutorialTitle=Programming Linux sockets, Part 2: Using UDP