server software design examples
play

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,


  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 NTUT, TAIWAN 1

  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) NTUT, TAIWAN 2

  3. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Iterative, Connectionless Server (UDP) NTUT, TAIWAN 3

  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 NTUT, TAIWAN 4

  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 NTUT, TAIWAN 5

  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 NTUT, TAIWAN 6

  7. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Process Structure AP server Socket at well-known port OS used for all communication NTUT, TAIWAN 7

  8. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Example The UDPtimed.c example NTUT, TAIWAN 8

  9. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Iterative, Connection-Oriented Server (UDP) NTUT, TAIWAN 9

  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 NTUT, TAIWAN 10

  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 NTUT, TAIWAN 11

  12. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Process Structure AP server OS Socket for Socket for connection an individual requests connection NTUT, TAIWAN 12

  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 NTUT, TAIWAN 13

  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 NTUT, TAIWAN 14

  15. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Concurrent, Connection- Oriented Servers (TCP) NTUT, TAIWAN 15

  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 NTUT, TAIWAN 16

  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? NTUT, TAIWAN 17

  18. Mobile Computing & Software Engineering Lab Mobile Computing & Software Engineering Lab Process Structure Application Master Processes (or threads) slave 1 slave 2 slave n OS Socket for Sockets for connection individual requests connections NTUT, TAIWAN 18

  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 NTUT, TAIWAN 19

  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 NTUT, TAIWAN 20

  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 NTUT, TAIWAN 21

  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 NTUT, TAIWAN 22

  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 NTUT, TAIWAN 23

Recommend


More recommend