Network programming for PyS60 (IV)
by Marcelo Barros
Network programming is innocuous if you don’t have at least some basic knowledge about IP addressing. So, that is our goal in this fourth post about networking programming for PyS60.
In IPv4 (Internet Protocol version 4) any networked device is addressed by a 32 bits number. This number is commonly represented as a sequence of four decimal numbers, each one representing one byte. These four decimal numbers are separated by dots for better understanding. For instance, valid IP addresses could be 188.8.131.52 or 10.20.30.40. Since each number is representing one byte (8 bits), they may vary from 0 to 255. As we will see, some combinations are not valid for addressing machines and there are some reserved IPs.
We have three types of addresses in IPv4: unicast, multicast and broadcast. Unicast is the typical situation that we usually call point to point connection. In this case you want to connect only to a specific target and this target must have an exclusive address. Several protocols uses unicast addressing, like when you are surfing on the Internet (HTTP), reading your email (SMTP) or transferring a file via FTP. However, if you want to write only one message and address it to several machines, you might use a multicast or broadcast address.
Multicast addresses are tied to the concept of a group of machines, not to a specific machine address. When you use a multicast address, you can reach all machines in that group. Machines that want to belong to a group must do it explicitly, joining to the group via a socket API call. The group is, in fact, an IP address from a reserved range, as I will see later. Finaly, Broadcast addresses are similar to multicast but less “selective”: the messages are sent to all machines (no subscription required) in a specific subnet or in the current local area network, if the subnet is not specified.
It is easy to understand how the IPv4 space addressing was divided when we use my “IP Addressing Circle”. If you consider that all possible IPv4 addresses are in the circle, half of these addresses starts with 0 in the most significant bit of first byte (0XXXXXXXb). This define what we call class A IP addresses. In the other half, we have only bytes with 10 or 11 in the first two most significant bits. The quarter starting with 10XXXXXXb is called class B IP addresses and the other quarter is divided again using the same logic among class C IP address (110XXXXXb), class D IP address (1110XXXXb) and class E IP address (1111XXXXb). Classes A, B e C are used for unicast, class D is used for multicast and class E is reserved.
With this division rule in your mind, we can calculate all IP address ranges just inspecting the first byte. For instance, for class A (0XXXXXXXb), the first number is when we put all X’s in zero and the last number when we set all X’s to one. In this case, we will have 00000000b and 01111111b or 0 and 127, in decimal. The following table summarizes these ranges.
Got it ? When you see an IP address like 184.108.40.206, this IP belongs to class B network. And it is simple to detect just observing the first number.
Each unicast address (Class A, B and C) is divided in two parts, known as network ID and Host ID. Depending on the class, a different number of bits is allocated to each one. Three differents partition were created to allow a variable number of hosts in a network, as depicted below.
The reasoning in this division is that machines in the same network must have the same Network IDs and, of course, different Host IDs. For instances, machines 10.10.23.1 and 10.100.55.3 belong to the same network (10) and have different host IDs (10.23.1 and 100.55.3). However, this kind of division was inefficient, generating a poor usage of the space addressing and a new partitioning scheme was created: CIDR (Classless Inter-Domain Routing).
Yes, but it will be explained only in the next post ! Do not miss it !
- Network programming for PyS60 (V) Before some more practicing, it is time to finish the...
- Network programming for PyS60 (XI) We have already talked about IP addressing in the post...
- Network programming for PyS60 (XIII) In our last post we talked about multicast, a special...
- Network programming for PyS60 (XII) Until now we have used only TCP in our examples...
- Network programming for PyS60 (III) As I promised, today we will start with some programming,...
Related posts brought to you by Yet Another Related Posts Plugin.