WS24_BST-BCS-16A
COMPUTER NETWORKS
Arno Fischer
Introductions 1
• Professor: Arno Fischer
• 3. Semester CS Students (You must attend at least 60 percent
of all events!)
• Content of course is partly based on the books Computer
Networks and Internet, Douglas E. Comer and LINUX
programming, Richard Stones and Neil Matthew
• Grading is based on knowledge gained (you must write a test)
and active participation in the exercises (you must give a short
presentation about networking issues and about your
programming work and hand in program code and
presentations)
16.10.2024 Arno Fischer ©2024 SRH Berlin 2
Introductions 2
• Theorie: mainly based on the content of the slides and some extra
calculation exercises demonstrated
• active participation:
• Short presentation of some network services (based on youtube
videos)
• Use of wireshark
• Programming in c using stuff from Comer or Stones, sockets,
client/server Applications with visual studio code and/or shell-
terminal
• Programming in python using stuff from neuralnine network
Applications using PyCharm CE and shell
16.10.2024 Arno Fischer ©2024 SRH Berlin 3.
Introductions 3
• You can build groups (up to three persons)
• You can come up with your own programming suggestions, but
you must have my approval
• Groups cannot be changed after selection
• Let‘s do it now
16.10.2024 Arno Fischer ©2024 SRH Berlin 4
Topic And Scope (Theory)
• Computer networks and internets: an overview of concepts,
• terminology, and technologies that form the basis for digital
• communication in individual networks and the global Internet
16.10.2024 Arno Fischer ©2024 SRH Berlin 5
MODULE I
Approaches To Networking, Open And
Closed Systems, Protocols, And Layering
16.10.2024 Arno Fischer ©2024 SRH Berlin 6
You Will Learn
• Fundamental principles
• Concepts
• Terminology (lots of it)
• Key aspects of networking
16.10.2024 Arno Fischer ©2024 SRH Berlin 7
The Five Key Aspects Of Networking
• Data communications: signals over wires and bits over signals
• Networks: packets over bits
• Internets: datagrams over packets
• Network programming: application data over the Internet
• Cross-functional concepts and technologies: network configuration,
control, and management
16.10.2024 Arno Fischer ©2024 SRH Berlin 8
Features Of The Course
• Covers all of networking and internetworking from media to
applications
• Examines each of the underlying technologies
• Focuses on concepts and principles that apply across vendors and
products
• Provides perspective and shows how the pieces fit together
• Explains how an Internet is built from heterogeneous networks
16.10.2024 Arno Fischer ©2024 SRH Berlin 9
What You Will Not Learn
• Commercial aspects
• Vendors
• Products
• Prices
• Markets and marketing
• How to engineer network equipment
• How to configure/operate networks
• How to design new protocols
16.10.2024 Arno Fischer ©2024 SRH Berlin 10
Practice Sessions
• Form an important part of the course
• You will
• Build network programs (using software from Comer and Stones, neuralnine)
• Capture and analyze packets (e.g. wireshark)
• Learn about protocols
16.10.2024 Arno Fischer ©2024 SRH Berlin 11
Background Expected
• Our goal is breadth rather than depth
• Only a few basics are needed
• Ability to program in C
• A glancing acquaintance with data structures and pointers
• A minor brush with algebra
• A basic understanding of operating systems
• The major requirement is a desire to learn
16.10.2024 Arno Fischer ©2024 SRH Berlin 12
Summary Of The Course
• Explores all aspects of networking and internetworking
• Gives concepts and principles
• Focuses on the big picture
• Includes lots of programming exercises
• Moves rapidly and covers lots of vocabulary (there is a large number
of abbreviations)
16.10.2024 Arno Fischer ©2024 SRH Berlin 13
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 14
Historic Approaches To
Networking
16.10.2024 Arno Fischer ©2024 SRH Berlin 15
How Should A Network Be Structured?
• The early phone company answer
• Data networking is like telephone calls
• We will devise and offer various data services
• Charges will depend on distance and duration
• You only need 128 Kbps
• The early computer vendor answer
• A network connects computers in your organization
• We will devise all the necessary equipment and software
• You only need to connect our computers
• You only need to run our applications
16.10.2024 Arno Fischer ©2024 SRH Berlin 16
How Should A Network Be Structured?
(continued)
• The early network equipment vendor answer
• The network is independent of computers
• We will create network equipment and interface hardware that connects
computers to our network
• We will build device drivers for your operating system
• You only need to use our network
16.10.2024 Arno Fischer ©2024 SRH Berlin 17
Some Resulting Commercial Network
Systems
• Apple Computer Appletalk
• Banyan Vines
• Digital Equipment Corporation DECNET
• IBM SNA
• Novell Netware
• Ungermann Bass NET/ One
• Xerox XNS
16.10.2024 Arno Fischer ©2024 SRH Berlin 18
The Researcher’s Answer
• Although we have computers at multiple sites, we reject the phone
company’s approach
• Because we use diverse computer architectures, we reject the
computer vendors’ approach
• Because a variety of network technologies are possible, we reject the
network vendors’ approach
• A variety of applications are possible
• Let’s experiment with new technologies (short distance as well as long
distance) and new applications
16.10.2024 Arno Fischer ©2024 SRH Berlin 19
Some Resulting Research Projects
• Xerox Palo Alto Research Center
• Ethernet
• MIT and elsewhere
• Token passing ring networks
• Department of Defense
• ARPANET
• SATNET
• Packet radio net
• The global Internet
16.10.2024 Arno Fischer ©2024 SRH Berlin 20
Open Vs. Closed Networking
• Closed networks
• Vertical approach
• Each vendor designs/ builds their own
• Given technology owned by vendor
• Vendor may license technology to other groups
• Open networks
• Competitive approach
• Multiple groups collaborate to define a technology
• To insure interoperability, specifications written in standards documents that are
available to everyone
• Companies build products according to standards
16.10.2024 Arno Fischer ©2024 SRH Berlin 21
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 22
Protocol Standards
And Protocol Design
Why Standardize?
• Networking supports communication among multiple entities
• Agreement needed to make communication correct, efficient, and
meaningful
16.10.2024 Arno Fischer ©2024 SRH Berlin 24
Which Organizations Issue Standards?
• IEEE (Institute of Electrical and Electronics Engineers)
• IETF (Internet Engineering Task Force)
• ITU (International Telecommunications Union)
• ISO (International Organization for Standardization)
• W3C (World Wide Web Consortium)
• ...and many others
16.10.2024 Arno Fischer ©2024 SRH Berlin 25
Standards And Standardization
• Joke: why is networking so difficult?
• Because there are so many standards from which to choose
16.10.2024 Arno Fischer ©2024 SRH Berlin 26
Protocol
• Each protocol specifies how to handle one aspect of communication
• A protocol can specify
• Low-level details such as voltage and frequency
• High-level details such as format visible to a user
• Many individual communication protocol standards exist
• Set of protocols designed to work together is known as a suite
• Example: TCP/ IP Internet protocol suite
16.10.2024 Arno Fischer ©2024 SRH Berlin 27
Two Key Properties That Protocols
Specify
• Syntax
• Format of each message
• Representation of data items
• Encoding of bits in electromagnetic signals
• Semantics
• Meaning of each message
• Procedures used to exchange messages
• Actions to take when an error occurs
16.10.2024 Arno Fischer ©2024 SRH Berlin 28
Steps In Protocol Design
• Look at the facilities the underlying hardware provides
• Imagine an abstract communication mechanism as a user would like it
to work
• Design an efficient implementation of the abstraction
• The key to success: choose a good abstraction
16.10.2024 Arno Fischer ©2024 SRH Berlin 29
Why Protocol Design Is Difficult
• Multiple implementations of a protocol will exist
• Implementations will be created by a multiple
individuals/organizations
• There are many details to consider
• Key tradeoff
• A specification that dictates all possible details restricts implementations
• specification that does not specify enough details is ambiguous and leads to
incompatible implementations
16.10.2024 Arno Fischer ©2024 SRH Berlin 30
Maximizing Interoperability
• Design principle that maximizes interoperability (due to Postel)
Be conservative in what you send
and be liberal in what you accept.
Jon Postel wrote this in an early version of the TCP specification in 1980, and it has since been
referred to as Postel's Law.
16.10.2024 Arno Fischer ©2024 SRH Berlin 31
Protocol Layering
and Layering Models
Protocol Layering
• Needed because communication is complex
• Intended primarily for protocol designers
• Divides communication into intellectually manageable pieces
• Provides a conceptual framework that can help us understand
protocols
• Ideally, layering is invisible once protocols have been designed
• Notes:
• Layering gives a guideline, not a rigid framework
• Optimizations may violate strict layering
16.10.2024 Arno Fischer ©2024 SRH Berlin 33
Two Layering Models
• Internet protocols use a 5-layer reference model
• ISO and the ITU defined a 7-layer model
16.10.2024 Arno Fischer ©2024 SRH Berlin 34
Two Layering Models
• Internet protocols use a 5-layer reference model
• ISO and the ITU defined a 7-layer model
16.10.2024 Arno Fischer ©2024 SRH Berlin 35
Internet Reference Model
• Descriptive model formed after TCP/IP protocols were devised
• Used in practice
16.10.2024 Arno Fischer ©2024 SRH Berlin 36
Physical Layer
• Underlying transmission media
• Electromagnetic energy and its use
• Representation of information in signals
• Electrical properties such as radio frequencies and voltage
• Associated hardware
16.10.2024 Arno Fischer ©2024 SRH Berlin 37
Network Interface Layer
• Communication between a computer and network hardware
• Also called data link or MAC layer
• Mechanisms for gaining access to shared media
• Hardware (MAC) addressing
• Packet (frame) formats
• Packet (frame) types and demultiplexing
• Error detection
16.10.2024 Arno Fischer ©2024 SRH Berlin 38
Internet Layer
• Communication between a pair of computers across the Internet
• Internet packet format (datagram)
• Internet addressing model and address assignment
• Forwarding of Internet packets
• Dividing an Internet packet into smaller packets for transmission
• Error detection and reporting
16.10.2024 Arno Fischer ©2024 SRH Berlin 39
Transport Layer
• Communication between a pair of applications
• Demultiplexing among multiple destinations on a computer
• Reliable delivery and retransmission
• Mechanisms to control data rate and avoid congestion
16.10.2024 Arno Fischer ©2024 SRH Berlin 40
Application Layer
• Format and representation of data and messages
• Procedures applications follow to
• Transfer data
• Handle errors or unexpected conditions
• Meaning of messages exchanged
• Internet infrastructure such as routing and DNS
16.10.2024 Arno Fischer ©2024 SRH Berlin 41
General Idea
• Each computer contains an entire set of layered protocols
• When an application sends a message
• The message passes down through the layered protocols
• A given layer adds information and forms a packet
• The computer transmits the final packet
• When a packet arrives
• The packet passes up through the protocol layers
• A given layer performs processing and passes the packet up to the next layer
• The application receives the message that was sent
16.10.2024 Arno Fischer ©2024 SRH Berlin 42
Illustration Of Protocol Software On A
Computer
• Protocols on a computer arranged in a conceptual stack
16.10.2024 Arno Fischer ©2024 SRH Berlin 43
Packet Headers As A Packet Passes
Across The Internet
• One header prepended by each layer when message sent
• Result: headers are nested with lowest-layer header appearing first
16.10.2024 Arno Fischer ©2024 SRH Berlin 44
Layering Principle
• Layered protocols enforce an invariant:
Layer N at the destination receives an exact copy of the
message sent by layer N at the source. All headers and other
modifications added by lower layers at the source must be
removed by lower layers at the destination.
• Allows protocol designer to focus on one layer at a time
16.10.2024 Arno Fischer ©2024 SRH Berlin 45
Illustration Of The Layering Principle
16.10.2024 Arno Fischer ©2024 SRH Berlin 46
Do We Understand Layering?
No!
16.10.2024 Arno Fischer ©2024 SRH Berlin 47
A Few Subtle Complications Of
Layering
• Layering diagrams are abstract and simplistic
• Details and exceptions complicate practical systems
• Four examples
• Cross-layer communication
• Multiple protocols per layer
• Layering in an Internet
• Technologies that intertwine layers
16.10.2024 Arno Fischer ©2024 SRH Berlin 48
Example Of Cross-Layer
Communication
• Facts
• A transport protocol selects amount of data to send in each packet
• To optimize performance, ensure packets are full
• Unfortunately
• To find maximum packet size, transport protocol must interact with a lower
layer
16.10.2024 Arno Fischer ©2024 SRH Berlin 49
Multiple Protocols Per Layer
• Consider a typical computer
• User can run multiple applications simultaneously
• Email
• Web browser
• Computer can connect to multiple physical networks
• Wired Ethernet
• Wi-Fi wireless network
• Other layers have multiple protocols as well
16.10.2024 Arno Fischer ©2024 SRH Berlin 50
Illustration Of Multiple Protocols At
Each Layer
16.10.2024 Arno Fischer ©2024 SRH Berlin 51
Layering In An Internet
• Our layering diagrams only show two computers connected to a
network
• The Internet contains multiple networks interconnected by routers
• Routers only need layer 2 and layer 3 software to forward packets
across the Internet
16.10.2024 Arno Fischer ©2024 SRH Berlin 52
Illustration Of Layers Used To Forward
Packets Across The Internet
• In practice, routers do more than forward packets
• We will learn more later in the course
16.10.2024 Arno Fischer ©2024 SRH Berlin 53
Technologies That Intertwine Layers
• Cross-layer functions
• Routing protocols operate at layer 5 but change layer 3 forwarding tables
• Address resolution maps layer 3 addresses to layer 2 addresses
• Layer circularities
• Tunneling can be used to send IPv6 (a layer 3 protocol) over IPv4 (another
layer 3 protocol)
• Virtual Private Networks (VPNs) send IP over IP
16.10.2024 Arno Fischer ©2024 SRH Berlin 54
Illustration Of Layering Used By A
VPN
16.10.2024 Arno Fischer ©2024 SRH Berlin 55
Two Layering Models
• Internet protocols use a 5-layer reference model
• ISO and the ITU defined a 7-layer model
16.10.2024 Arno Fischer ©2024 SRH Berlin 56
ISO 7-Layer Reference Model
• Prescriptive model formed before
protocols were devised
• Created by committee vote
16.10.2024 Arno Fischer ©2024 SRH Berlin 57
ISO 7-Layer Reference Model
(continued)
• Model was defined when data networks connected dumb terminals to
large mainframes
• Session layer
• Handled details of login and control of send/ receive
• Provided opportunity for billing and accounting
• Presentation layer
• Defined data representation
• Primary intention was to map character sets
• Both layers now superfluous
16.10.2024 Arno Fischer ©2024 SRH Berlin 58
Unfortunately
• Marketing organizations decided seven is better than five
• Many textbooks and vendors claim to use “all seven layers”
16.10.2024 Arno Fischer ©2024 SRH Berlin 59
Summary
• Network systems can be open or closed
• Closed systems are created and owned by a single company
• Open systems require that technology be specified in standards documents that
allow multiple companies to build products
• A protocol standard can specify data and message representation, rules
for message exchange, error handling, or low-level details such as
voltage
16.10.2024 Arno Fischer ©2024 SRH Berlin 60
Summary
(continued)
• A layering model provides a conceptual framework that helps protocol
designers create a suite of protocols
• Implementation of layered protocols known as a stack
• Internet uses a 5-layer reference model
• Remainder of the course explores each layer
16.10.2024 Arno Fischer ©2024 SRH Berlin 61
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 62
An Alternative To Layering
Hire really, really smart people and have them design a single,
large protocol that handles all aspects of communication
without dividing the problem into smaller subproblems
16.10.2024 Arno Fischer ©2024 SRH Berlin 63
A List Of All Practical
Alternatives To Layering
(this page intentionally left blank)
16.10.2024 Arno Fischer ©2024 SRH Berlin 64
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 65
MODULE II
Network Programming And Applications
16.10.2024 Arno Fischer ©2024 SRH Berlin 66
Topics
• Internet services and communication paradigms
• Client-server model and alternatives
• Network programming with a simplified API (Comer)
• The socket API (Stones)
• Application layer protocols
• Examples of standard application protocols
16.10.2024 Arno Fischer ©2024 SRH Berlin 67
Internet Services And
Communication Paradigms
16.10.2024 Arno Fischer ©2024 SRH Berlin 68
General Principle: Intelligence At The
Edge
The Internet does not provide services. Instead, the
Internet only provides communication, and application
programs provide all services.
• Consequence
• Every Internet communication, including voice and video teleconferencing, involves
communication among application programs Computer
16.10.2024 Arno Fischer ©2024 SRH Berlin 69
Communication Paradigms
• The Internet offers two communication paradigms
• Each paradigm has surprising characteristics
16.10.2024 Arno Fischer ©2024 SRH Berlin 70
Stream Paradigm (TCP)
• Transfers a sequence of bytes
• Connection-oriented: data sent between two applications
• Bidirectional (one stream in each direction)
• No meaning attached to data and no boundaries inserted in data
• Surprising characteristic:
Although it delivers all bytes in sequence, the stream
paradigm does not guarantee that the chunks of bytes
passed to a receiving application correspond to the
chunks of bytes transferred by the sending application.
16.10.2024 Arno Fischer ©2024 SRH Berlin 71
Message Paradigm (UDP)
• Connectionless: network accepts and delivers individual messages
• If the sender places N bytes in a message, a receiver will find exactly
N bytes in the incoming message
• Paradigm allows unicast, multicast, or broadcast delivery (one
destination, multiple destinations, or all destinations)
• Surprising characteristic:
Although it preserves boundaries, the message paradigm
allows messages to be lost, duplicated, or delivered outof-
order; neither the sender nor receiver is informed
when such errors occur.
16.10.2024 Arno Fischer ©2024 SRH Berlin 72
Stream Transport And Data Chunks
• The protocol system may
• Divide the data from the sender into multiple segments and deliver a few bytes
at a time to the receiver
• Combine data from multiple transmissions into a single large chunk and
deliver it to the receiver all at once
• Consequence: receiving application cannot know exactly which pieces
were sent
16.10.2024 Arno Fischer ©2024 SRH Berlin 73
Example #1
• Assume a stream connection between two applications
• Sender
• Places 1000-byte message in buffer buf
• Makes a single request to send all 1000 bytes
• Receiver
• Allocates a buffer b with 1000 bytes
• Reads 1000 bytes from the stream into buffer b
• The OS may return between 1 and 1000 bytes
• Application must make repeated calls until all 1000 bytes have been
acquired
16.10.2024 Arno Fischer ©2024 SRH Berlin 74
Example #2
• Assume a stream connection between two applications
• Sender transmits a sequence of four messages that are each 100 bytes
long
• Receiver allocates a large buffer b of 1000 bytes and requests that up
to 1000 bytes from stream be read into buffer b
• The OS may choose to return all four messages (400 bytes) with a
single read request
• Receiving application must be able to separate received data into four
separate messages
16.10.2024 Arno Fischer ©2024 SRH Berlin 75
Programming Hints
• When using the stream paradigm
• Devise a way that a receiver knows where a message ends
• Read from a socket until the entire message has been acquired
• When considering using the message paradigm
• Don’t (at least not yet)
16.10.2024 Arno Fischer ©2024 SRH Berlin 76
Identifying Individual Messages
In A Stream
• Possibilities
• Send exactly one message followed by end of file (EOF)
• Send multiple messages with an integer length before each message
• Send multiple messages with a termination character (or sequence) following
each message
• Notes
• Any technique can be used as long as both sides agree
• If sending a multi-byte length value or multi-byte termination sequence,
remember that the application may need multiple calls receive all bytes
16.10.2024 Arno Fischer ©2024 SRH Berlin 77
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 78
Questions
• In a realistic setting
• Is division of a message likely to occur?
• Is aggregation of multiple messages likely to occur?
• Answers yes! (depending on the size of the messages)
• Messages larger than 1400 characters are usually divided into multiple packets
for transmission, and may be delivered together or separately
• The stream service is designed to aggregate small messages before making
them available to a receiving application
16.10.2024 Arno Fischer ©2024 SRH Berlin 79
Buffering In The Stream Paradigm
• Aggregation, which makes bulk transfer more efficient, can occur on the
sending or receiving side
• The stream paradigm includes a push operation that an application can use
to force transmission and delivery
• Unix convention: automatically push for each individual write call
• Programming hints
• To ensure a small message is transmitted and delivered without delay, use a separate
write
• Even with push, network delays mean applications must be written to tolerate
aggregation
• More details later in the course
16.10.2024 Arno Fischer ©2024 SRH Berlin 80
Client-Server Model
And Alternatives
16.10.2024 Arno Fischer ©2024 SRH Berlin 81
Client-Server Model Of Interaction
• Used by applications to establish communication
• One application acts as a server
• Starts execution first
• Awaits contact
• The other application becomes a client
• Starts after server is running
• Initiates contact
• Important concept: once communication has been established, data
(e.g., requests and responses) can flow in either direction between a
client and server
16.10.2024 Arno Fischer ©2024 SRH Berlin 82
Characteristics Of A Client
• Arbitrary application program that becomes a client temporarily
• Usually invoked directly by a user, and usually executes only for one
session
• Actively initiates contact with a server, exchanges messages, and then
terminates contact
• Can access multiple services as needed, but usually contacts one
remote server at a time
• Runs locally on a user’s personal computer or smart phone
• Does not require especially powerful computer hardware
16.10.2024 Arno Fischer ©2024 SRH Berlin 83
Characteristics Of A Server
• Special-purpose, privileged program dedicated to providing a service
• Usually designed to handle multiple remote clients at the same time
• Invoked automatically when a system boots, and continues to execute
through many client sessions
• Waits passively for contact from arbitrary remote clients and then
exchanges messages
• Requires powerful hardware and a sophisticated operating system
• Runs on a large, powerful computer
16.10.2024 Arno Fischer ©2024 SRH Berlin 84
Characteristics Of A Server
• Special-purpose, privileged program dedicated to providing a service
• Usually designed to handle multiple remote clients at the same time
• Invoked automatically when a system boots, and continues to execute
through many client sessions
• Waits passively for contact from arbitrary remote clients and then
exchanges messages
• Requires powerful hardware and a sophisticated operating system
• Runs on a large, powerful computer
16.10.2024 Arno Fischer ©2024 SRH Berlin 85
Server Programs And Server-Class
Computers
• Confusion exists between scientific and marketing terminology
• Scientific: a client and a server are each programs
• Marketing: a server is a powerful computer connection
16.10.2024 Arno Fischer ©2024 SRH Berlin 86
Summary Of Client-Server Interaction
16.10.2024 Arno Fischer ©2024 SRH Berlin 87
Illustration Of Steps Taken By Client
And Server
16.10.2024 Arno Fischer ©2024 SRH Berlin 88
Alternatives To Client-Server
• Broadcast
• Sender broadcasts message and all stations receive it
• Does not scale well (becomes inefficient)
• Difficult to restrict data access
• Rendezvous point
• Intermediary connects communicating applications
• In essence, there are two clients and a server
• Rendezvous point becomes a bottleneck
16.10.2024 Arno Fischer ©2024 SRH Berlin 89
Alternatives To Client-Server
(continued)
• Peer-To-Peer Interaction
• Designed to avoid central server bottleneck
• Data divided among N computers
• Each computer acts as a server for its data and as a client for other data
• Given computer receives 1 / N of the traffic
16.10.2024 Arno Fischer ©2024 SRH Berlin 90
Network Programming
• General term that refers to the creation of client and server
applications that communicate over a network
• Programmer uses an Application Program Interface (API)
• Set of functions
• Include control as well as data transfer functions (e.g., establish and terminate
communication)
• Defined by the operating system; not part of the Internet standards
• Socket API has become a de facto standard
16.10.2024 Arno Fischer ©2024 SRH Berlin 91
Some Simplified Examples
• Will help you get started
(Appendix 1, Douglas E.Comer, Computer Networks and Internets, 6.Edition)
• General idea
• Server is identified by pair (computer, application)…(only Comer‘s API)
• Server starts first and waits for contact
• Client specifies server’s location
• Once a connection is established, client and server can exchange data
• Only seven functions to program in C
16.10.2024 Arno Fischer ©2024 SRH Berlin 92
Some Simple Examples
• Will help you get started
(Chapter 14 sockets, „Beginning Linux Programming, 2. Edition, Richard Stones/Neil Matthew)
• General idea
• – Server is identified by pair (IP-address, Port-number)..(only
Stones)
• – Server starts first and waits for contact
• – Client specifies server’s location
• – Once a connection is established, client and server can exchange
data
• Only simple functions to program in C
16.10.2024 Arno Fischer ©2024 SRH Berlin 93
The Socket API
16.10.2024 Arno Fischer ©2024 SRH Berlin 94
Sockets
• Originally part of BSD Unix
• Now standard in the industry
• AT&T defined an alternative named TLI (Transport Layer Interface),
but TLI is now extinct
• Almost every OS includes an implementation
• MS Windows chose to make minor changes (annoying)
16.10.2024 Arno Fischer ©2024 SRH Berlin 95
Socket Characteristics
• Socket can be used for
• Connectionless communication (UDP message)
• Connection-oriented communication (TCP stream)
• Many functions in the API
• Approach
• Create a socket
• Make many function calls to specify type of communication, remote
computer’s address, port number to be used, etc.
• Use socket to send / receive data
• Close the socket (terminate use)
16.10.2024 Arno Fischer ©2024 SRH Berlin 96
Example Socket Calls For Stream
Communication
16.10.2024 Arno Fischer ©2024 SRH Berlin 97
Application Layer Protocols
16.10.2024 Arno Fischer ©2024 SRH Berlin 98
Terminology
• Availability of an application protocol
• Closed — vendor defines a protocol for their products
• Open — standardized and available for all vendors
• Basic protocol types
• Data representation — message and data formats
• Data transfer — procedures for exchanging messages and handling unexpected
/ error conditions
• Notes
• Application may define separate protocol for each type
• Term Transfer in a protocol title indicates the latter
16.10.2024 Arno Fischer ©2024 SRH Berlin 99
Defining An Application Layer Protocol
• Programmer specifies representation
• Format of each message and each data item
• Meaning of each item in a message
• Programmer specifies transfer
• Which side sends first
• Which side closes the connection first
• What to do if one side crashes unexpectedly
16.10.2024 Arno Fischer ©2024 SRH Berlin 100
State In An Application Protocol
• Big decision: should state information be kept?
• Stateful protocol assumes previous requests have been honored
• Stateless protocol assumes each request is independent
• Example of stateful interaction
• Request 1 specifies “read from file X”
• Request 2 specifies “read next 128 bytes”
• Example of stateless interaction
• Request 1 specifies “read bytes 0-127 from file X”
• Request 2 specifies “read bytes 128-255 from file X”
16.10.2024 Arno Fischer ©2024 SRH Berlin 101
Examples Of Standard
Application Protocols
16.10.2024 Arno Fischer ©2024 SRH Berlin 102
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 103
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 104
Application-Layer Protocols For The Web
• Reminder: keyword Transfer in the name of a protocol means the
protocol specifies message exchange
16.10.2024 Arno Fischer ©2024 SRH Berlin 105
HyperText Markup Language (HTML)
• Representation standard for multimedia documents
• Specifies document is entirely in printable text
• Uses declarative rather than procedural approach
• Document includes metadata that can link to arbitrary item
• Document contains markup guidelines rather than precise, detailed
formatting or typesetting instructions
• Page can be displayed on arbitrary device
• Appearance depends on device
• Embedded tags control display
• Form is <tag_name> and </tag_name>
16.10.2024 Arno Fischer ©2024 SRH Berlin 106
Uniform Resource Locator (URL)
• Representation standard
• A text string with punctuation characters separating the string into
(optional) subfields
• General form is:
protocol:// computer_name : port / document_name ? parameters
• Example where port, and parameters are omitted:
https://www.srh-berlin.de/hochschule/hochschulteam/hartmann-michael/
16.10.2024 Arno Fischer ©2024 SRH Berlin 107
HyperText Transfer Protocol (HTTP)
• Transfer protocol used with the Web
• Specifies format and meaning of messages
• Each message represented as text
• Transfers arbitrary binary data
• Can download or upload data
• Incorporates caching for efficiency
• Browser sends request to server
16.10.2024 Arno Fischer ©2024 SRH Berlin 108
Four Major HTTP Request Types
• GET request has the form:
GET /item version CRLF
• Version is HTTP/1.0 or HTTP/1.1
16.10.2024 Arno Fischer ©2024 SRH Berlin 109
HTTP Response
• Response begins with a header in text, optionally followed by an item
(which can be binary)
• Header uses keyword: information form like email header
• Header ends with a blank line
16.10.2024 Arno Fischer ©2024 SRH Berlin 110
HTTP Header Format
• General form
HTTP/1.0 status_code status_string CRLF
Server: server_identification CRLF
Last-Modified: date_document_was_changed CRLF
Content-Length: datasize CRLF
Content-Type: document_type CRLF
CRLF
... item begins here and contains datasize bytes ...
16.10.2024 Arno Fischer ©2024 SRH Berlin 111
Telnet Example (Apache Web Server)
$ telnet www.srh-berlin.de 80
Trying 167.233.14.16...
Connected to www.srh-berlin.de .
Escape character is ’^]’.
GET /hochschule/hochschulteam/hartmann-michael/ HTTP/1.0
HTTP/1.1 200 OK
Date: Mon, 10 Oct 2022 11:38:27 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8r
Last-Modified: Mon, 17 Oct 2021 22:21:41 GMT
ETag: "bafb0-a50-4af8607f7c740"
Accept-Ranges: bytes
Content-Length: 2640
Connection: close
Content-Type: text/html
...data from the web page follows here
16.10.2024 Arno Fischer ©2024 SRH Berlin 112
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 113
Original End-To-End Email Paradigm
• Each computer runs
• Email server to accept incoming email
• Email client to send outgoing email
• Incoming mail deposited in user’s mailbox
• Outgoing mail placed in queue
• User interface to read or compose messages separate from transfer
applications
16.10.2024 Arno Fischer ©2024 SRH Berlin 114
Current Email Paradigm
• User’s mailbox located on separate computer (usually at an ISP)
• Mail transfer application deposits message in mailbox
• User interface application accesses remote mailbox
• A web browser may be used as an access mechanism
• Special-purpose applications also exist
16.10.2024 Arno Fischer ©2024 SRH Berlin 115
Simple Mail Transfer Protocol (SMTP)
• Standard for email transfer
• Follows a stream paradigm
• Uses textual control messages
• Only transfers text messages
• Terminates message with <CR> <LF> . <CR> <LF>
• Allows a sender to specify recipients’ names and checks each name
• Sends only one copy of a message to a computer, even if destined to
multiple recipients on the computer
16.10.2024 Arno Fischer ©2024 SRH Berlin 116
Example SMTP Session
• S: 220 somewhere.com Simple Mail Transfer Service Ready
• C: HELO example.edu
• S: 250 OK
• C: MAIL FROM:<Olaf.Scholz@example.edu>
• S: 250 OK
• C: RCPT TO:<Christian.Lindner@somewhere.com>
• S: 550 No such user here
• C: RCPT TO:<Robert.Habeck@somewhere.com>
• S: 250 OK
• C: DATA
• S: 354 Start mail input; end with <CR><LF>.<CR><LF>
• C: ...sends body of mail message, which can contain
• C: ...arbitrarily many lines of text
• C: <CR><LF>.<CR><LF>
• S: 250 OK
• C: QUIT
• S: 221 somewhere.com closing transmission channel
16.10.2024 Arno Fischer ©2024 SRH Berlin 117
Mail Access Protocols
• Two standard protocols
• Post Office Protocol version 3 (POP3)
• Internet Mail Access Protocol (IMAP)
• Functionality
• Provide access to a user’s mailbox
• Permit user to view headers, download, delete, or send individual messages
• Client runs on user’s personal computer
• Server runs on a computer that stores user’s mailbox
16.10.2024 Arno Fischer ©2024 SRH Berlin 118
RFC2822 Mail Message Format
• Email representation standard
• Name derived from the Internet standard in which it is defined
• Specifies
• Email message consists of text file
• Blank line separates header from body
• Header lines have the form:
Keyword: information
16.10.2024 Arno Fischer ©2024 SRH Berlin 119
RFC2822 Mail Message Format
(continued)
• Some keywords have defined meanings:
• From:
• To:
• Subject:
• Cc:
• Keywords starting with uppercase X have no effect
• Examples:
• X-Best-networking-Course: Computer Networks
• X-Spam-Check-Results: bulk spam 90% likely
• X-Worst-TV-Shows: any reality show
16.10.2024 Arno Fischer ©2024 SRH Berlin 120
Multimedia Email
• Observe
• Email was standardized when computers only had character-oriented (textual)
interfaces
• SMTP is limited to transferring plain text messages
• Users want to email photos, spreadsheets, messages with special fonts and
color
• Question: can SMTP be used to transfer such email?
• Answer: it is possible because one can encode arbitrary binary items in
plain text (think of a hex dump)
16.10.2024 Arno Fischer ©2024 SRH Berlin 121
Sending Non-Text Email
• Standard is MIME (Multimedia Internet Mail Extensions)
• Backward compatible with RFC2822 mail and SMTP
• Sender
• Encodes arbitrary binary item in plain text
• Adds lines to email header to specify MIME
• Places additional headers before each item in the message (including plain text
items)
• Sender can specify content type and encoding
• Standard includes Base64 encoding
16.10.2024 Arno Fischer ©2024 SRH Berlin 122
Examples Of Mime Headers
• MIME header lines added to other RFC2822 headers
MIME-Version: 1.0
Content-Type: Multipart/Mixed; Boundary=xyz123
• Each part of the message has a MIME header that starts with the separator
and specifies content type and encoding
• Example
--xyz123
Content-Type: image/jpeg
<---blank line ends header
16.10.2024 Arno Fischer ©2024 SRH Berlin 123
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 124
File Transfer
• Standard is the File Transfer Protocol (FTP)
• Once accounted for the most packets on the Internet
• Interesting communication paradigm
• Client forms a control connection to send requests
• Server forms data connection for each file transferred
• Server closes data connection after transfer complete
• Notes
• Using a separate connection allows arbitrary data transfer
• For data connections, the server becomes a client and the client becomes a
server (important for NAT)
16.10.2024 Arno Fischer ©2024 SRH Berlin 125
Illustration Of FTP Communication
16.10.2024 Arno Fischer ©2024 SRH Berlin 126
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 127
Remote Login And Remote Desktop
• Remote login
• Intended for systems with command-line interface
• Internet standard is TELNET
• Secure shell (ssh) encrypts transfers
• To appreciate the complexity of application protocols look at the TELNET
standard
• Remote desktop
• Intended for systems that have a Graphical User Interface (GUI)
• No Internet standards
• Move to thin client has revived interest
16.10.2024 Arno Fischer ©2024 SRH Berlin 128
Application Protocol Examples
• Web browsing
• Email
• File transfer
• Remote login and remote desktop
• Domain Name System (name lookup)
16.10.2024 Arno Fischer ©2024 SRH Berlin 129
Domain Name System (DNS)
• Important piece of Internet infrastructure
• Runs at the application layer
• Translates human-readable names into the binary addresses used by
the Internet Protocol
• Example
• Computer www.srh-berlin.de
• Has the IP address 167.233.14.16
shell command: nslookup www.srh-berlin.de
16.10.2024 Arno Fischer ©2024 SRH Berlin 130
DNS Terminology
• Names are hierarchical
• Each name divided into segments by period character, which is read
“dot”
• Most significant segment is on the right
• Rightmost segment known as a top-level domain (TLD)
• Client program known as a resolver
• Used by web browser, email, etc
16.10.2024 Arno Fischer ©2024 SRH Berlin 131
Top-Level Domains
16.10.2024 Arno Fischer ©2024 SRH Berlin 132
Top-Level Domains
(continued)
• In 2014, ICANN decided to allow many new TLDs
16.10.2024 Arno Fischer ©2024 SRH Berlin 133
Domain Registration
• Organization
• Applies under a specific top-level domain
• Can choose an internal hierarchy
• Assigns each computer a name
• Geographic registration is possible
cnri.reston.va.us
• Some countries impose conventions
• Universities in Great Britain register under
ac.uk
16.10.2024 Arno Fischer ©2024 SRH Berlin 134
Domains With Most Hosts (July 2013)
See domain survey at
www. isc . org for
details
16.10.2024 Arno Fischer ©2024 SRH Berlin 135
Host Names and Services Offered
• Many organizations choose a host name to match the service a
computer offers
mail.foobar.com
ftp.foobar.com
www.foobar.com
• Although convenient for humans, a host name does not specify which
servers are running (e,g., a computer named mail could run a web
server)
16.10.2024 Arno Fischer ©2024 SRH Berlin 136
DNS Servers
• Names divided into a hierarchy of servers
• Multiple groupings possible
• Hypothetical example
16.10.2024 Arno Fischer ©2024 SRH Berlin 137
Name Resolution And Caching
• Resolver
• Acts as a client
• Is configured with address of local DNS server
• Contacts local server first
• Socket library resolver is gethostbyname
• Caching
• Follows locality of reference principle
• Each DNS server caches results
• Cached item never kept when stale
16.10.2024 Arno Fischer ©2024 SRH Berlin 138
DNS Server Algorithm Part 1
Given:
A request message from a DNS name resolver
Provide:
A response message that contains the address
Method:
Extract the name, N, from the request
if ( server is an authority for N ) {
Form and send an authoritative response
to the requester;
else if ( answer for N is in the cache ) {
Form and send a nonauthoritative response
to the requester;
16.10.2024 Arno Fischer ©2024 SRH Berlin 139
DNS Server Algorithm Part 2
else { /* Need to look up an answer */
if ( authority server for N is known ) {
Send request to authority server;
} else {
Send request to root server;
}
Receive response and place in cache;
Form and send a response to the requester;
}
16.10.2024 Arno Fischer ©2024 SRH Berlin 140
Summary
• Applications provide all Internet services
• Internet offers connection-oriented stream communication or
connectionless message communication
• Most applications follow client-server approach
• Server starts first and awaits client
• Client contacts server
• Socket API is a de facto standard
• Application-layer protocol can define
• Data and message formats (representation)
• Rules for message exchange (transfer)
16.10.2024 Arno Fischer ©2024 SRH Berlin 141
Summary
(continued)
• Applications reviewed include
• Web (URL, HTML, HTTP)
• Email (SMTP, RFC2822, MIME)
• File transfer (FTP)
• Remote login and remote desktop (TELNET)
• Domain Name System (DNS)
16.10.2024 Arno Fischer ©2024 SRH Berlin 142
Questions?
Questions?
16.10.2024 Arno Fischer ©2024 SRH Berlin 143
Questions?
This Photo by Unknown Author is licensed under CC BY-NC
16.10.2024 Arno Fischer ©2024 SRH Berlin 144