Professional Documents
Culture Documents
CT047-3-2-SPCC
Prepared by: KL First Prepared on: 9-09-07 Last Modified on: Quality checked by: xxx Copyright 2007 Asia Pacific Institute of Information Technology
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
Client-Server Model
Relationship Concurrency
Processes
Relationship
A computer runs a program to either request a service from another computer or provide a service to another computers.
Application programs, running at two end computers and communicating with each other, are needed.
Enabling communication between two application programs, one running at the local site and the other running at the remote site. Many question arise when we want to implement the approach. Q. Should both the applications be able to request services, or should they just do one. A. An application program, called the client, running on the local machine request a service from another application program, called the server, running on the remote machine.
CT014-1 Hardware, Systems Software and Networks
Client-server model
Relationship
Q. Should an application program provide services only to one specific application program installed somewhere in an internet, or should it provide services for any application program that request this service? A. A server providing service for any client, not a particular client.
Q.
A.
When should an application program be running all the time or just when there is a need for the service? A client program, which request a service, should run only when it is needed. The server program, which provides a service, should run all the time because it does not know when its services will be needed.
Relationship
Q. Should there be only one universal application program that can provide any type of service a user wants? Or should there be one application program for each type of service? A. In the internet, services needed frequently and by many users have specific client-server application programs such Internet Explore, Firefox, Mozilla and so on. We do have separate client-server application programs that allow users to access files or send email such windows mail, FTP, office outlook and so on. Services that are more customized, we should have one generic application program that allows users to access the services available on a remote computer.
Client-server relationship
Client
A client is a program running on the local machine requesting service from a server. A client program is started by the user and terminates when the service is complete.
A client opens the communication channel using the IP address of the remote 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.
CT014-1 Hardware, Systems Software and Networks
Server
A server is a program running on the remote machine and providing service 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 is called a passive open. A server program is an infinite program. It waits for incoming requests from clients. When a request arrives, it responds to the request.
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.
Concurrency
Concurrency in Servers An iterative server can process only one request at a time; it receives a request, processes it, and sends the response to the requestor before it handle another request. A concurrent server can process many requests at the same time.
TCP are normally concurrent. Server can serve many clients at the same time.
CT014-1 Hardware, Systems Software and Networks
Processes
Most operating system, including UNIX, distinguish a program from a process.
Program and process are related to each other, they are not same thing.
In UNIX, a program is source code. It defines all the variables and actions to be performed on those variables. A process, on the other hand, is an instance of a program. When the OS can create several processes from one program, which means several instances of the same program are running at the same time (concurrently). Memory is allocated for each process separately.
CT014-1 Hardware, Systems Software and Networks
Socket Interface
Sockets Connectionless Iterative Server
Connection-Oriented Server
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 structure with five fields. 1. Family The protocol group: IPv4, IPv6, UNIX domain protocolsl 2. Type Stream socket, Packet Socket, or raw socket. 3. Protocol Set to zero for TCP and UDP 4. Local socket address A combination of the local IP address and the port address. 5. Remote socket address A combination of remote IP address and the port address.
CT014-1 Hardware, Systems Software and Networks
Socket structure
Socket types
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 connectionoriented 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 message from one application to another across the Internet. Raw Socket Some protocols such as ICMP or OSPF that directly use the services of IP use neither stream socket nor datagram socket.
CT014-1 Hardware, Systems Software and Networks
Server
1. 2. Create a socket Asks the OS to create a socket Bind Asks the OS to enter information in the socket related to the server. This is called binding the server socket. Repeat a) Received a request asks the OS to wait for a request b) Process Process by the server. c) Send Response to sent to the client.
3.
1. 2.
3. 4.
Create a socket Asks the OS to create a socket Bind Asks the OS to enter information in the socket related to the server. This is called binding the server socket. Listen Asks OS to listen to the client. TCP is a connection orientated protocol. Repeat a) Create a child - OS create temporary child process and 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 be used by the child process. c) Repeating Child repeats the following steps. Read child reads a stream of bytes Process Processes the stream of bytes Write Child writes the results as a stream of bytes to the connection. d) Destroy socket After the client has been served, the child process asks the OS to destroy the temporary socket
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 programs communicate with each other. One server program can provide services for many client 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 a time) or concurrently (many at a time).
CT014-1 Hardware, Systems Software and Networks
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 its transport 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 system and the other running on the remote system, need to communicate with each other, a network program is required.
CT014-1 Hardware, Systems Software and Networks
The socket interface is a set of declarations, definitions, and procedures for writing client-server programs.
Q&A
CT014-1 Hardware, Systems Software and Networks
Next Session
Lab View