ucti_spacc_06_client server model socket interface
TRANSCRIPT
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
1/35
Client-Server Model: Socket Interface
Prepared by: KL First Prepared on: 9-09-07 Last Modified on:Quality checked by: xxx
Copyright 2007 Asia Pacific Institute of Information Technology
Level-2
System Programming and Computer ControlCT047-3-2-SPCC
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
2/35
CT014-1 Hardware, Systems Software and Networks
Topic & Structure of the lesson
Client-Server Model
Socket Interface
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
3/35
CT014-1 Hardware, Systems Software and Networks
Key Terms you must be able touse
Active close Active open Application program Application programming
interface (API) Client Client-server model Concurrent client
Concurrent server Connectionless iterative server Connection-oriented concurrent
server
Datagram socket Iterative client Iterative server Process Raw socket Server Socket Socket interface Stream socket
If you have mastered this topic, you should be able to use the following termscorrectly in your assignments and exams :-
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
4/35
CT014-1 Hardware, Systems Software and Networks
Client-Server
M odel :
Socket I nter f ace
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
5/35
CT014-1 Hardware, Systems Software and Networks
Client and Server Programs
Client-server program are written in languages suchas C, C++, Java, Lab View and Perl.
This type of programming is very involved andrequires and advanced knowledge of programmingas well as knowledge of the particular language.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
6/35
CT014-1 Hardware, Systems Software and Networks
Client-Server Model
Rela t ionship
Concur rency
Processes
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
7/35
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
8/35CT014-1 Hardware, Systems Software and Networks
Client-server model
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
9/35CT014-1 Hardware, Systems Software and Networks
RelationshipQ. Should an application program provide services only to one
specific application program installed somewhere in an internet, orshould it provide services for any application program that requestthis service?
A. A server providing service for any client, not a particular client.
Q. When should an application program be running all the time or just when there is a need for the service?
A. A client program, which request a service, should run only when it
is needed. The server program, which provides a service, shouldrun all the time because it does not know when its services will beneeded.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
10/35CT014-1 Hardware, Systems Software and Networks
RelationshipQ. Should there be only one universal application program that can
provide any type of service a user wants? Or should there be oneapplication program for each type of service?
A. In the internet, services needed frequently and by many users havespecific client-server application programs such Internet Explore,Firefox, Mozilla and so on.We do have separate client-server application programs that allowusers to access files or send email such windows mail, FTP, officeoutlook and so on.
Services that are more customized, we should have one genericapplication program that allows users to access the servicesavailable on a remote computer.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
11/35CT014-1 Hardware, Systems Software and Networks
Client-server relationship
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
12/35CT014-1 Hardware, Systems Software and Networks
Client
A client is a program running on the local machine requesting servicefrom a server.
A client program is started by the user and terminates when theservice is complete.
A client opens the communication channel using the IP address of theremote host and the well-known port address of the specific server
program running on that machine. This is called an active open.
The client sends its request and receives a response. The whole process is finite and eventually comes to an end.
The client closes the communication channel with an active close.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
13/35CT014-1 Hardware, Systems Software and Networks
Server
A server is a program running on the remote machine and providingservice to the clients.
When it starts, it opens the door for incoming requests from clients, but it never initiates a service until it is requested to do so. This iscalled a passive open.
A server program is an infinite program.
It waits for incoming requests from clients. When a request arrives, itresponds to the request.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
14/35CT014-1 Hardware, Systems Software and Networks
Concurrency
Concurrency in Clients
Clients can be run on a machine either iteratively or
concurrently. Running clients iteratively means running them one by one; one client must start, run and terminate.
Concurrent clients ; that is, two or more clients can run
at the same time.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
15/35
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
16/35CT014-1 Hardware, Systems Software and Networks
Connectionless iterative server
UDP are normally iterative. Server processes one requestat a time.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
17/35CT014-1 Hardware, Systems Software and Networks
Connection-oriented concurrent server
TCP are normally concurrent. Server can serve manyclients at the same time.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
18/35
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
19/35
CT014-1 Hardware, Systems Software and Networks
Socket Interface
Sockets
Con n ect io n less Iterat ive Server
Con n ect io n -Oriented Server
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
20/35
CT014-1 Hardware, Systems Software and Networks
Socket Interface The Socket Interface was originally based on UNIX
and defines a set of system calls (Procedures). Communication structure need in socket programming
and it is define in the operating system as a structurewith five fields.
1. Family The protocol group: IPv4, IPv6, UNIXdomain protocolsl
2. Type Stream socket, Packet Socket, or raw socket.
3. Protocol
Set to zero for TCP and UDP4. Local socket address A combination of the local IPaddress and the port address.
5. Remote socket address A combination of remote IP
address and the port address.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
21/35
CT014-1 Hardware, Systems Software and Networks
Socket structure
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
22/35
CT014-1 Hardware, Systems Software and Networks
Socket types
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
23/35
CT014-1 Hardware, Systems Software and Networks
Socket types The Socket Interface defines three types of sockets: the
stream socket , the packet socket , and the raw socket. A stream socket is designed to be used with a connection-
oriented protocol such as TCP. It is connect one
application program to another across the Internet. A Datagram Socket is designed to be used with a
connectionless protocol such as UDP. It send a messagefrom one application to another across the Internet.
Raw Socket Some protocols such as ICMP or OSPF thatdirectly use the services of IP use neither stream socket nordatagram socket.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
24/35
CT014-1 Hardware, Systems Software and Networks
Connectionless Iterative Server
Iterative client-server communication using UDPand datagram sockets.
The server pay no attention to the other packets.
The packets from one client or from many client,are store in a queue, waiting for service. They are processed one by one by in order of arrival.
The server uses one single well-known port; Allthe packets arriving at this port wait in line to beserved.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
25/35
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
26/35
S k i f f i i d
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
27/35
CT014-1 Hardware, Systems Software and Networks
Socket interface for connection-oriented concurrentserver
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
28/35
CT014-1 Hardware, Systems Software and Networks
Connection-Oriented Concurrent Server Concurrent client-server communication using Iterative TCP and
stream socket. This server serves many client at the same time . It is a stream of bytes that could arrive in several segments , and the
response could occupy several segments. The connection remains open until the entire stream is processed, and
then the connection is terminated . The server must have one buffers for each connection. It use parent and child servers. A parent server use well known port and running infinitely and
accepting connection from clients is called a parent server. The parent server creates a child server and an ephemeral port and letsthe child server handle the client.
It free itself so that it can wait for another connection and server canserve several clients concurrently.
C ti O i t d C t S
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
29/35
CT014-1 Hardware, Systems Software and Networks
Connection Oriented Concurrent ServerFunction
Clients1. Create a socket Asks
the OS to create a socket.2. Connect asks the OS to
make a connection.3. Repeat
a) Write Client sends
a stream of bytes tobe sent to theserver.
b) Read The clientreceives a stream ofbytes from theserver.
4. Destroy After theclient has finished, itasks the operatingsystem to destroythe socket . Theconnection is also
closed .
Server1. Create a socket Asks the OS to create a socket
2. Bind
Asks the OS to enter information in the socketrelated to the server. This is called binding the serversocket .
3. Listen Asks OS to listen to the client. TCP is aconnection orientated protocol.
4. Repeat
a) Create a child - OS create temporary child processand assigns the duty of serving the client to the child.The parent process it free to listen for new clients.
b) Create a new socket - .A new socket is created to beused by the child process.
c) Repeating Child repeats the following steps.
Read
child reads a stream of bytesProcess Processes the stream of bytesWrite Child writes the results as a stream of bytesto the connection.
d) Destroy socket After the client has been served, thechild process asks the OS to destroy the temporary
socket
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
30/35
CT014-1 Hardware, Systems Software and Networks
Quick Review Questions
Refer to tutorial question.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
31/35
CT014-1 Hardware, Systems Software and Networks
Summary Client-Server Model: Socket Interface
In the client-server model, the client runs a program
to request a service and the server runs a program to provide the service. These two programscommunicate with each other.
One server program can provide services for manyclient programs.
Clients can be run either iteratively (one at a time)or concurrently (many at a time).
Servers can handle clients either iteratively (one at atime) or concurrently (many at a time).
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
32/35
CT014-1 Hardware, Systems Software and Networks
Summary Client-Server Model: Socket Interface
A connectionless iterative server uses UDP as its transport
layer protocol and can serve one client at a time.
A connection-oriented concurrent server uses TCP as itstransport layer protocol and can serve many clients at the
same time. When the operating system executes a program, an instance
of the program, called a process, is created.
If two application programs, one running on a local systemand the other running on the remote system, need tocommunicate with each other, a network program isrequired.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
33/35
CT014-1 Hardware, Systems Software and Networks
Summary Client-Server Model: Socket Interface The socket interface is a set of declarations, definitions, and
procedures for writing client-server programs.
The communication structure needed for socket programming is called a socket.
A stream socket is used with a connection-oriented protocolsuch as TCP.
A datagram socket is used with a connectionless protocolsuch as UDP.
A raw socket is sued by protocols such as ICMP or OSPFthat directly use the services of IP.
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
34/35
CT014-1 Hardware, Systems Software and Networks
Q & A
Question and Answer Session
-
8/13/2019 UCTI_SPACC_06_Client Server Model Socket Interface
35/35
Next Session
Lab View