Download presentation
Presentation is loading. Please wait.
1
Serial-Server Strategy Two way channel is for additional interaction between client and server Initial client request serves to establish two way communication channel Communication channel is private – not accessable to other processes A busy server handling long-lived requests cannot use serial server strategy ServerClient Client Request Two-Way Communication
2
Serial-Server Pseudocode for (;;) { listen for client request; create private two-way communication channel; while (no error on communication channel) read client request; handle request and respond to client; close communication channel }
3
Parent-Server Strategy Server resumes listing for more requests Server forks a child to handle actual service Similar to switchboard at hotel Server can accept multiple client requests ServerClient Client Request Server Child Two-Way Communication fork
4
Parent-Server Pseudocode for (;;) { listen for client request; create a private two-way communication channel; fork a child to handle the request; close the communication channel; clean up zombies; }
5
Thread-Server Strategy Low overhead alternative to parent-server strategy Create thread to handle request instead of forking child – threads have less overhead Efficient if request is small or I/O intensive Possible interference among multiple requests due to shared address space For computationally intensive services, additional threads may reduce efficiency of or block the main server thread Requires good kernel-level parallelism Server Threads Client Client Request Two-Way Communication
6
Call rcp cougar path1 path2 argv[0] = rcp argv[1] = cougar argv[2] = path1 argv[3] = path2
7
Client Send Path1 Client Bundle up path1 and send to serverusing network communications write(commfd, argv[2], sizeof(argv[2]));
8
Server Receive Path1 for ( ; ; ) { if ((bytesread = read(commfd, p_buf, BLKSIZE)) < 0) { read error; break; } else if (bytesread == 0) { break; } t_fd = open(p_buf, O_RDONLY);
9
Server Read Path1 into s_buf and Send Contents to Client for ( ; ; ) { if ((bytesread = read(t_fd, s_buf, BLKSIZE)) < 0) { file read error; break; } else if (bytesread == 0) { break; } else if (bytesread != write(commfd, s_buf, (size_t)bytesread)) { server write error; break; } }
10
Client Receive p2fd = open(argv[3], O_WRONLY); for ( ; ; ) { if ((bytes_read = read(commfd, c_buf, BLKSIZE)) 0; bufp += bytes_written, bytes_to_write -= bytes_written){ bytes_written = write(p2fd, bufp, bytes_to_write); if ((bytes_written) == -1 && (errno != EINTR)){ client write error; break; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.