Introduction to TCP and Sockets

This section is an introduction to TCP/IP programming using a sockets API. (Sockets can also be used to work with other network protocols, such as IPX/SPX and Appletalk, but that is beyond the scope of this document.) The standard socket API was originally developed in the Unix world, but was ported to the /400 operating system as part of the "Unix-like" APIs, and a modified version was also ported to the Windows platform as "Windows Sockets" (or "Winsock" in abbreviated)

Usually when someone refers to "TCP/IP", they are referring to the full suite of protocols, all based on the Internet Protocol ("IP"). Unlike a single network, where each computer is directly connected to all other computers, an "internetwork" (or "internet") is a collection of one or more networks. These networks are all connected together to form a larger “virtual network”. Any host on this virtual network can exchange data with any other host, referring to the hosts "address".

The address is a 32-bit number unique across the Internet. Typically, this number is split into 4 8-bit chunks, separated by dots to make it easier for humans to read. This human-readable format is called "dotted decimal" format, or simply "dot notation". An address displayed this way looks something like "192.168.66.21".

Different parts of this "IP address" are used to identify what network a host is on, and the rest of the address is used to identify the host itself. Which part of the address and which part is the host is determined by a "netmask" (or "netmask" for short.) The netmask is another 32-bit number that acts as a "guide " to the IP address. Each bit set in the netmask means that the corresponding bit in the IP address is part of the network address. Each disabled bit means that the corresponding bit in the IP address is part of the host address.

Here is an example IP address and netmask:

dotted decimal same number in binary format: ------------------------------------------------ IP address: 192.168.66.21 11000000 10101000 01000010 00010101 Netmask: 255.255.255.0 11111111 11111111 11111111 00000000 The network address is: 192.168.66 11000000 10101000 01000010 The host address is: .21 00010101

A slightly more complicated example:

dotted decimal same number in binary format: ------------------------------------------------ IP address: 192.168.41.175 11000000 10101000 00101001 10101111 Netmask: 255.255.255.248 11111111 11111111 11111111 11111000 The network address is: 192.168.41.168 11000000 10101000 00101001 10101 The host address is: 7111

When a system sends data over the network using the Internet Protocol, the data is sent in fixed-length data records called datagrams. (These are sometimes called "packets") The datagram consists of a "header" followed by a "data section". The header contains addressing information, much like an envelope you send through your local postal service. The header contains a "destination" and a "return" address, as well as other information used by the Internet Protocol. Another similarity between IP and your postal service is that every packet sent is not guaranteed to arrive at its destination. Although every effort is made to achieve this, datagrams do occasionally get lost or duplicated in transit. Also, if you send 5 datagrams at once, there is no guarantee that they will arrive at their destination at the same time or in the same order.

What's really needed is a simple way to ensure that all packets sent get to their destination. When they arrive, make sure they are in the same order and any duplicate datagrams are removed. To solve this problem, the Transmission Control Protocol (TCP) was created. It works on top of IP and takes care of making sure that every packet sent will make it to its destination. It also allows many packets to be grouped into a "continuous stream" of bytes, saving you the trouble of splitting your data into packets and rejoining them at the other end.

It is useful to remember that TCP runs "on top" of IP. This means that any data you send over TCP is converted into one or more datagrams, then sent over the network over IP, and then reassembled into a data stream at the other end.

TCP is a "connection-oriented protocol", which means that when you want to use it, you must first "establish a connection". To do this, one program must play the role of "server", and another p...

This section is an introduction to TCP/IP programming using a sockets API. (Sockets can also be used to work with other network protocols, such as IPX/SPX and Appletalk, but that is beyond the scope of this document.) The standard socket API was originally developed in the Unix world, but was ported to the /400 operating system as part of the "Unix-like" APIs, and a modified version was also ported to the Windows platform as "Windows Sockets" (or "Winsock" in abbreviated)

Usually when someone refers to "TCP/IP", they are referring to the full suite of protocols, all based on the Internet Protocol ("IP"). Unlike a single network, where each computer is directly connected to all other computers, an "internetwork" (or "internet") is a collection of one or more networks. These networks are all connected together to form a larger “virtual network”. Any host on this virtual network can exchange data with any other host, referring to the hosts "address".

The address is a 32-bit number unique across the Internet. Typically, this number is split into 4 8-bit chunks, separated by dots to make it easier for humans to read. This human-readable format is called "dotted decimal" format, or simply "dot notation". An address displayed this way looks something like "192.168.66.21".

Different parts of this "IP address" are used to identify what network a host is on, and the rest of the address is used to identify the host itself. Which part of the address and which part is the host is determined by a "netmask" (or "netmask" for short.) The netmask is another 32-bit number that acts as a "guide " to the IP address. Each bit set in the netmask means that the corresponding bit in the IP address is part of the network address. Each disabled bit means that the corresponding bit in the IP address is part of the host address.

Here is an example IP address and netmask:

dotted decimal same number in binary format: ------------------------------------------------ IP address: 192.168.66.21 11000000 10101000 01000010 00010101 Netmask: 255.255.255.0 11111111 11111111 11111111 00000000 The network address is: 192.168.66 11000000 10101000 01000010 The host address is: .21 00010101

A slightly more complicated example:

dotted decimal same number in binary format: ------------------------------------------------ IP address: 192.168.41.175 11000000 10101000 00101001 10101111 Netmask: 255.255.255.248 11111111 11111111 11111111 11111000 The network address is: 192.168.41.168 11000000 10101000 00101001 10101 The host address is: 7111

When a system sends data over the network using the Internet Protocol, the data is sent in fixed-length data records called datagrams. (These are sometimes called "packets") The datagram consists of a "header" followed by a "data section". The header contains addressing information, much like an envelope you send through your local postal service. The header contains a "destination" and a "return" address, as well as other information used by the Internet Protocol. Another similarity between IP and your postal service is that every packet sent is not guaranteed to arrive at its destination. Although every effort is made to achieve this, datagrams do occasionally get lost or duplicated in transit. Also, if you send 5 datagrams at once, there is no guarantee that they will arrive at their destination at the same time or in the same order.

What's really needed is a simple way to ensure that all packets sent get to their destination. When they arrive, make sure they are in the same order and any duplicate datagrams are removed. To solve this problem, the Transmission Control Protocol (TCP) was created. It works on top of IP and takes care of making sure that every packet sent will make it to its destination. It also allows many packets to be grouped into a "continuous stream" of bytes, saving you the trouble of splitting your data into packets and rejoining them at the other end.

It is useful to remember that TCP runs "on top" of IP. This means that any data you send over TCP is converted into one or more datagrams, then sent over the network over IP, and then reassembled into a data stream at the other end.

TCP is a "connection-oriented protocol", which means that when you want to use it, you must first "establish a connection". To do this, one program must play the role of "server", and another p...

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow