If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Beginning Network Programming in Python

[glowpurple] A BEGINNER'S GUIDE TO NETWORK PROGRAMMING IN PYTHON - PART I/III[/glowpurple]

This tutorial introduces the basics of network programming in Python. I'm planning to divide this tutorial into three parts. The first one will cover some basics and details about a few useful functions from the socket module in Python.

ABOUT PYTHON

Python would be the best language for a beginner to start with in the
world of programming. Programming languages tend to obey an inverse complexity
versus simplicity relationship. Take C for instance; the programmer has to worry
about a lot of details of the program which gives him greater control but in turn
makes it more difficult for him to code. For the rest of us who aren't hardcore
programmers trying to play God (Most of us ;-) ), a language more inclined to
simplicity would be the best choice to start learning.

Python is an interpreted, interactive, object-oriented programming language. Best of all,
its open source. It can be dowloaded freely at

"Python - why settle for snake oil when you can have the whole snake?"

—From Usenet posting by Mark Jackson, June 1998

NETWORK PROGRAMMING BASICS

Some of the basic concepts required to understand this tutorial are given below.

IP ADDRESS:

An ip address is a 32-bit address used to identify a computer in the Internet. Therefore
every computer present in the Internet has a unique ip address. This 32 bit is divided
into four equal parts ( 8-bits ) which are separated by dots. Each address consists of a network number,
an optional subnetwork number, and a host number.

For eg. 165.113.245.2

Each part having just 8-bits can have values ranging from 0 to 255 ( 2^8 =256 values ). But, 0 and
255 are used for special purposes and are not used to specify a particular box.

PORTS:

"A Port is a connection point for different protocols to communicate on different machines"
For eg. port number 80 is used for HTTP traffic. Try using the command "netstat -a" while
surfing the web to see the various ports involved in the activity. To get a complete listing
of well known ports, check this site out -&gt; http://www.iana.org/assignments/port-numbers

SOCKETS:

"Sockets are used as endpoints for sending and receiving data between computers."
When i'm using my browser to access www.antionline.com, my browser( good ol' firefox)
creates a socket requesting connection to the site. At the same time, the antionline
webserver has a socket listening for connections. In this way sockets are used to send
data between the two boxes. A socket is bound to an ip-address and a port.

TRANSPORT LAYER:

The transport layer is the fourth layer of the seven layer OSI-ISO model. The transport layer
provides for transport of messages between boxes. The two protocols working in this layer are
TCP ( Transmission Control Protocol ) and UDP ( User Datagram Protocol ). The former provides
a very reliable form of communication. TCP employs a technique called a three way handshake.
UDP on the other hand is known as a connectionless protocol and is very unreliable. I'm only
talking about the transport layer of the OSI-ISO model as it is necessary to understand the
difference between UDP and TCP while creating a socket. For more on the OSI-ISO model, check
out the site -&gt; http://www.pcsupportadvisor.com/OSI_...odel_page1.htm

NETWORK PROGRAMMING IN PYTHON

The "sockets" module in Python is quite similar to that in C. C network programmers will find it easy
as cake to master python network programming. Throughout the tutorial, i'll use "&gt;&gt;&gt;" to indicate the
CLI of the Python interactive interpreter. The statement followed by "#" is a comment and is not
interpreted.

inet_ntoa(packedform) is used to convert it back to the ip address form, the details of which
are self explanatory...( feeling lazy !)

This brings an end to the first part of this tutorial. The next part will deal with socket creation,
deletion and sending data between boxes. Thank you for spending your time to read my little tutorial.

The tutorial is underdone, what you have provided yet, are merely simple definitions ... I would highly recommend a Re-done to the tutorial and more effort would boosts the professionalism of the tutorial in general ....

Cheers

\"The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts\".....SpafEverytime I learn a new thing, I discover how ignorant I am.- ... Black Cluster

Thanks for the reply Black Cluster. I intended to keep the first part very fundamental and to cover the more programming aspects in the coming parts. Anyway i shall make more changes
to increase the depth and professionalism. :-)