| Winsock & .NET | Winsock | < Linux Socket Index | TCP/IP Client Server Model > |


 

 

 

 

 

NETWORK PROGRAMMING

LINUX SOCKET PART I: THE FUNDAMENTALS

 

 

 

 

 

 

 

 

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

 

Advanced Winsock2 Tutorial

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.

 

The 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 briefly.

  • 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.

A physical network connection illustration

Figure 1

 

 

 

 

 

 

 

 

 

 

 

 

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

  1. FTP (file transfer protocol).

  2. SMTP (simple mail transfer protocol).

  3. telnet (remote logins).

  4. rlogin (simple remote login between UNIX machines).

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

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

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

  8. SNMP (simple network management protocol).

Protocol

TCP and UDP Protocols

  1. Transmission Control Protocol is defined by RFC-793.

  2. TCP provides connection-oriented transport service and reliable.

  3. End-to-end transparent byte-stream.

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

  1. User Datagram Protocol is defined by RFC-768.

  2. UDP provides datagram service that is a packet based.

  3. Connectionless.

  4. Unreliable.

  5. E.g.: NFS, TFTP.

Port numbers and services

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 - Internet Protocol version 6

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. GCC, GDB and other related tools.

 

 

 

 


 

 | Winsock & .NET | Winsock | < Linux Socket Index | TCP/IP Client Server Model > |