| Winsock | Main | TCP/IP Client Server Model | Site Index | Download |


 

NETWORK PROGRAMMING

SOCKET PART I

 

 

 

Are you a computer nerd?  If you have ever wanted to  Learn computer HTML, sign online today.  Make a career out of your computer skills!  You can get an  Associates Degree in Computer education, or you can get a  Technology Associates education Degree.  If you want to learn about computers and the internet, there is no better time than today!

 

 

 

 

 

Menu

 

Network Story 1

 

Network Story 2

 

Network Story 3

 

Network Story 4

 

Network Story 5

 

Network Story 6

 

Socket Example 1

 

Socket Example 2

 

Socket Example 3

 

Socket Example 4

 

Socket Example 5

 

Socket Example 6

 

Socket Example 7

 

Advanced TCP/IP 1

 

Advanced TCP/IP 2

 

Advanced TCP/IP 3

 

Advanced TCP/IP 4

 

Advanced TCP/IP 5

My Training Period:  xx hours

 

Note:  Program examples if any, compiled using gcc on Linux Fedora Core 3 machine with several update, as normal user.  The Fedora machine used for the testing having the "No Stack Execute" disabled and the SELinux set to default configuration.

 

Abilities that supposed to be acquired:

 

         Able to understand the basic of client-server model.

         Able to understand the TCP/IP suite/stack/layer.

         Able to understand important protocols such as TCP and UDP.

         Able to understand and use the Unix/Linux C language socket APIs.

         Able to understand and implement several simple Client and server basic designs.

 

This Tutorial introduces a network programming using sockets.  Some of the information is implementation specific but all the program examples run on Fedora 3 and compiled using gcc.  The following are topics that will be covered.

 

         Some Background Story.

         The Client-Server Model.

         Concurrent Processing.

         Programming Interface.

         The Socket Interface.

         Client Design.

         Example Clients.

         Server Design.

         Iterative, Connectionless Servers (UDP).

         Iterative, Connection-Oriented Servers (TCP).

         Concurrent, Connection-Oriented Servers (TCP).

         Single-Process, Concurrent Servers (TCP).

         Multi protocol Servers.

         Multi service Servers.

         Managing Server Concurrency.

         Client Concurrency.

 

Some Background Story

 

  • This background story tries to introduce the terms used in network programming and also to give you the big picture.

  • The following figure is a typical physical network devices connection.

Physical network connection illustration

Figure 1

  • Using a simple network shown in the above Figure, let trace the data stream flow from Network A to Network B, by assuming that Network A is company A’s network and Network B is company B’s network.

  • Physically, the flow of the data stream is from a computer in Network A (source) will go through the hub, switch and router.

  • Then the stream travel through the carrier such as Public Switch Telephone Network (PSTN) and leased line (copper, fiber or wireless – satellite) and finally reach Network B’s router, go through the switch, hub and finally reach at the computer in company B (destination).

  • And from the previous network devices layout, the OSI (Open System Interconnection) 7 layer stack mapping is shown below.

7 OSI layers

Figure 2

 

OSI Layer

Function provided

Application

Network application such as file transfer and terminal emulation

Presentation

Data formatting and encryption.

Session

Establishment and maintenance of sessions.

Transport

Provision for end-to-end reliable and unreliable delivery.

Network

Delivery of packets of information, which includes routing.

Data Link

Transfer of units of information, framing and error checking.

Physical

Transmission of binary data of a medium.

 

Table 1

OSI layer vs TCP/IP stack

Figure 3

OSI layer vs TCP/IP stack applications

Figure 4

TCP/IP information flows

Figure 5

         FTP (file transfer protocol).

         SMTP (simple mail transfer protocol).

         telnet (remote logins).

         rlogin (simple remote login between UNIX machines).

         World Wide Web (built on http) and https (secure http).

         NFS (network filing system – originally for Sun Microsystems).

         TFTP (trivial file transfer protocol – used for booting).

         SNMP (simple network management protocol).

Protocol

TCP and UDP

         Transmission Control Protocol is defined by RFC-793.

         TCP provides connection-oriented transport service and reliable.

         End-to-end transparent byte-stream.

         E.g.: FTP, telnet, http, SMTP.

         User Datagram Protocol is defined by RFC-768.

         UDP provides datagram service that is a packet based.

         Connectionless.

         Unreliable.

         E.g.: NFS, TFTP.

 

Port numbers

IP address & port of server + IP address & port of client

Numeric IP Addresses

131.95.115.204

 

IP Address Classes

192.168.1.100

xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx

Byte 1.Byte 2.Byte 3.Byte 4

Class and Network size

Range (decimal)

Network ID

Host ID

Class A (Large)

1 -127

Byte 1

Bytes 2, 3, 4

Class B (Medium)

128 – 191

Bytes 1, 2

Bytes 3, 4

Class C (Small)

192 – 223

Bytes 1, 2, 3

Bytes 4

 

Table 2

0xxx = class A - bits 1-7 define a network. bits 8-31 define a host on that network. So we've128 networks with 16 million hosts.

10xx = class B - bits 2-15 define a network. bits 16-31 define a host on that network. So we've 16384 networks with 65536 hosts.

110x = class C - bits 3-23 define a network. bits 24-31 define a host on that network. So we've 2 million networks with 256 hosts.

 

Table 3

 

--------------------------------------------------------------------------

IPv4 IP address classes

Figure 6

Host Names and DNS

Ethernet Addresses

 

MAC and ARP protocol

ARP command

 

Figure 7

 

 

-------------------------------------------------------------------------------------------------

address resolution protocol - TCP/IP screen shots

 

Figure 8

IPv6

69DC:88F4:FFFF:0:ABCD:DBAC:1234:FBCD:A12B::F6

ipv6 comand run at DOS comand prompt

 

Figure 9

 

An example of the ipv6 command screen snapshots

 

Figure 10

 

Distributed Applications

Application Protocols

telnet computer.some.where [port_number]

telnet www.yahoo.com 23

Providing Concurrent Access to Services

…Continue on next Module…More in-depth discussion about TCP/IP suite is given in Advanced TCP/IP Tutorials.

 

 

 

Further reading and digging:

 

  1. Check the best selling C / C++, Networking, Linux and Open Source books at Amazon.com.
  2. Protocol sequence diagram examples.
  3. Another site for protocols information.
  4. RFCs.
  5. External Data Representation (XDR).
  6. Remote Procedure Call (RPC).

 

 

 

 

 

 

 | Winsock | Main | TCP/IP Client Server Model | Site Index | Download |


2003-2008 © Tenouk. All rights reserved.