Transcript Lecture 4

ICOM 6115 – Computer Networks
and the WWW
Manuel Rodriguez-Martinez, Ph.D.
Lecture 4
ICOM 6115
©Manuel Rodriguez-Martinez
Lecture Objectives
• Understand Network Programming
– Socket abstraction
• Stream Socket
• Datagram Socket
– Networking Support in the programming
language
• Java
– Operating Systems support for Networking
– Implementation options for servers
ICOM 6115
©Manuel Rodriguez-Martinez
Network Programming
• Client-server and P2P are the models to
organize application
– Architectural Framework
• How do we actually move data between
the components of the application?
– Sockets
– Provide abstraction of a file to perform I/O
• Send data to receiver
• Read data from sender
ICOM 6115
©Manuel Rodriguez-Martinez
The idea of OS File
Application
File
“MyLetter.doc”
Disk
ICOM 6115
©Manuel Rodriguez-Martinez
The OS File
• Provides mechanism to read related
blocks of bytes from disk
– Hides where they are on disk
• OS must keep track of this information
– File System
• Operations on files
– Create, Open, Close, Read, Write
• Need more sophistication: use streams
– Another layer on top of files
• Provides access to int, string, bytes, object, etc
ICOM 6115
©Manuel Rodriguez-Martinez
The Idea of Socket
• See the networks as a cable to which the
applications can connect.
• Socket is the place where the application
“plugs” itself to the network
– Every app. is using a socket to send/receive
• Associate a socket with two files
– One for reading from socket
– One for writing to socket
ICOM 6115
©Manuel Rodriguez-Martinez
Socket Abstraction
Client
IN
I/O Files
OUT
IN
Socket
OUT
Socket
Network
ICOM 6115
Server
©Manuel Rodriguez-Martinez
Communication between sockets
Client
Server
IN
IN
OUT
Socket
Socket
Network
ICOM 6115
OUT
©Manuel Rodriguez-Martinez
Types of Sockets
• Stream Socket
– Provide a reliable bytes stream between the
end-points
– Connection oriented
• TCP
• Datagram Socket
– Provide an unreliable byte stream between
the end-points
– Connectionless
• UDP
ICOM 6115
©Manuel Rodriguez-Martinez
Creating a Socket in Java
• Client sockets
– Destination host
– Port number
• Server Socket
– Port number
• Many other flags can be set
• Sockets can be encrypted
– SSL
– Custom-made
ICOM 6115
©Manuel Rodriguez-Martinez
Example Client and Server apps
• Basic Application
– Get the Date
• MyServer1.java
• MyClient1.java
• Another toy application
– Get the Date or nick name of the machine
– Illustrates the need for protocols
ICOM 6115
©Manuel Rodriguez-Martinez
Iterative Server
Client
Client
Client
Server
Listen Queue
OS
ICOM 6115
©Manuel Rodriguez-Martinez
Iterative Server
• One server to handle multiple requests
– Simple to implement
– Take some time to service each request
• Bottleneck if I/O is needed
– Should be used only to service small requests
• Time
• Name of a computer
– Typically used for connectionless services
• Datagrams
ICOM 6115
©Manuel Rodriguez-Martinez
Concurrent Server
Master
Server
ICOM 6115
Client
Client
Client
Slave
Server
Slave
Server
Slave
Server
©Manuel Rodriguez-Martinez
Concurrent Server
• Multiple serves to handle multiple requests
– Each client has its own server
• Master server – receives initial request
and forwards it to slaver server
• Slave server is the actual entity that
interacts with the client
• Issues
ICOM 6115
©Manuel Rodriguez-Martinez
Concurrent Servers (Issues)
• Issues
– More complex to implement
– Provides parallelism
• Good for I/O intensive applications
– Should be used to service large requests
• HTTP
• Database requests
– Typically used for connection-oriented
services
• TCP Applications
ICOM 6115
©Manuel Rodriguez-Martinez