Server Software Design Examples Chuan-Ming Liu Computer Science - - PowerPoint PPT Presentation

server software design examples
SMART_READER_LITE
LIVE PREVIEW

Server Software Design Examples Chuan-Ming Liu Computer Science - - PowerPoint PPT Presentation

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Server Software Design Examples Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology NTUT,


slide-1
SLIDE 1

NTUT, TAIWAN 1

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Server Software Design Examples

Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology

slide-2
SLIDE 2

NTUT, TAIWAN 2

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Examples

Iterative, Connectionless Server (UDP) Iterative, Connected-Oriented Server (TCP) Concurrent, Connection-Oriented Server (TCP)

slide-3
SLIDE 3

NTUT, TAIWAN 3

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Iterative, Connectionless Server (UDP)

slide-4
SLIDE 4

NTUT, TAIWAN 4

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Creating Passive Socket

To hide the allocation of socket, use

passiveUDP (passiveUDP.c) passiveTCP (passiveTCP.c)

two high-level procedures Both procedures call passivesock() to perform socket allocation – passivesock.c

slide-5
SLIDE 5

NTUT, TAIWAN 5

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Port Privilege

To use well-known services (lower port number), the server process needs special privilege Two servers on a given computer can not use the same port number at the same time How to overcome the port privilege?

Using portbase

slide-6
SLIDE 6

NTUT, TAIWAN 6

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Portbase

Programmer does not need to modify all references to port numbers – safety Solves the problem in general way – generality Solving the possible port conflicts – no conflicts

slide-7
SLIDE 7

NTUT, TAIWAN 7

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Process Structure

server

OS AP

Socket at well-known port used for all communication

slide-8
SLIDE 8

NTUT, TAIWAN 8

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Example

The UDPtimed.c example

slide-9
SLIDE 9

NTUT, TAIWAN 9

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Iterative, Connection-Oriented Server (UDP)

slide-10
SLIDE 10

NTUT, TAIWAN 10

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Creating Passive Socket

Use passiveTCP to allocate a stream socket and bind it to the well-known port Two arguments in passiveTCP:

Name of service Size of the queue for requests

slide-11
SLIDE 11

NTUT, TAIWAN 11

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Why Iterative?

Each request for the time is simple and easy to process Server does not need to optimize for speed

slide-12
SLIDE 12

NTUT, TAIWAN 12

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Process Structure

server

OS AP

Socket for connection requests Socket for an individual connection

slide-13
SLIDE 13

NTUT, TAIWAN 13

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Example

The TCPdaytimed.c example The call to accept blocks the server thread until a connection arrives

When a connection request arrives TCP protocol engages 3-way handshake to establish a connection After completing the handshake, the system allocates a new socket and the call to accept returns The server continues to execute

slide-14
SLIDE 14

NTUT, TAIWAN 14

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Connection Termination

Daytime server can close a connection Usually, the termination is decided by clients Allowing a client to control connection duration can be dangerous because it allows clients to control resource use Avoid vulnerability when designing servers

slide-15
SLIDE 15

NTUT, TAIWAN 15

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Concurrent, Connection- Oriented Servers (TCP)

slide-16
SLIDE 16

NTUT, TAIWAN 16

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Multiple Single-threaded Processes

Recall Algorithm 8.4 OS’s support for concurrent processing Master process for connection requests Slave processes for handling communication with clients Each process contains a single thread

slide-17
SLIDE 17

NTUT, TAIWAN 17

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Echo Service

Echo server responds to each client Alternates between reading and writing Closes the connection when it encounters an end-of-file condition Iterative or concurrent?

slide-18
SLIDE 18

NTUT, TAIWAN 18

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Process Structure

Master

OS Application Processes (or threads)

Socket for connection requests Sockets for individual connections slave1 slave2 slaven

slide-19
SLIDE 19

NTUT, TAIWAN 19

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Example – TCPechod.c

The call to accept blocks the server thread until a connection arrives Note the call to fork(): after the fork()

Master process needs to close the child socket The new child process needs to close the master socket Sockets only disappear in the processes not the system Before system deallocates a socket, all the processes own the socket need to close it

slide-20
SLIDE 20

NTUT, TAIWAN 20

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Exit call

Linux interprets the exit call as a request to terminate the process and uses the argument as a process exit code Conventionally, a process uses exit code zero to denote normal termination

slide-21
SLIDE 21

NTUT, TAIWAN 21

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Errant Processes

Incompletely terminated processes due to the dynamic allocation of processes Linux solves this by sending a signal to the parent whenever a child process exits

slide-22
SLIDE 22

NTUT, TAIWAN 22

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Errant Processes

Existing process remains in a zombie state until the parent executes a wait3 system call Server needs to catch the child termination signal and executes a signal handling function

slide-23
SLIDE 23

NTUT, TAIWAN 23

Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab

Signal

signal(SIGCHLD,reaper) informs the OS

The master process should execute reaper function whenever it receives a signal that a child process has exited

reaper function calls wait3() system call

To complete terminate a child that exits Wait3 blocks until one or more children exit WNOHANG argument specifies that wait3 should not block waiting for a process to exit