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]

Programming Linux sockets, Part 1: Using TCP/IP

Creating an echo server and client

David Mertz (mertz@gnosis.cx), 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 introductory-level tutorial shows how to begin programming with sockets. Focusing on C and Python, it guides you through the creation of an echo server and client, which connect over TCP/IP. Fundamental network, layer, and protocol concepts are described, and sample source code abounds.

View more content in this series

Date:  28 Oct 2003
Level:  Introductory PDF:  A4 and Letter (85 KB | 17 pages)Get Adobe® Reader®

Activity:  46587 views
Comments:  

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. While this tutorial focuses primarily on C programming, and also uses Python as a representative higher-level language for examples, a similar API is available in many languages.

This tutorial introduces you to the basics of programming custom network tools using the cross-platform Berkeley Sockets Interface. Almost all network tools in Linux and other UNIX-based operating systems rely on this interface.


Prerequisites

This tutorial requires a minimal level of knowledge of C, and ideally of Python also (mostly for the follow-on Part 2). However, if you are not familiar with either programming language, you 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, and so on.

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 Resources at the end of this tutorial for background documents).

1 of 8 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=133074
TutorialTitle=Programming Linux sockets, Part 1: Using TCP/IP
publish-date=10282003
author1-email=mertz@gnosis.cx
author1-email-cc=