[ Team LiB ] |
21.4 UDP Implementation with Multiple Programs and ReceiversThis section describes an implementation that allows both multiple programs and multiple receivers. 21.4.1 Multiple programs and one receiverCopy UDPSendSeq.c into UDPSendProg.c and compile it as UDPSendProg. Modify UDPSendProg to interpret the filename command-line argument as a program listing of available audio files. Each line of the program listing has the name of an audio file and a description. When the sender receives a request message consisting of a 0 byte, the sender transmits the contents of the program listing file to the receiver as a single message. (Assume that the listing file is small enough to be sent as a single UDP message.) When the sender receives a message containing a single nonzero integer in network byte order, the sender begins to transmit the audio file identified by that integer. A value of 1 represents the first file in the program listing. Any value out of range causes the sender to ignore the request message and resume listening for another request. Copy UDPRecvSeq.c into UDPRecvProg.c and compile it as UDPRecvProg. UDPRecvProg begins by sending a single 0 byte to the sender and reading the program listing. UDPRecvProg presents the listing to the user and prompts for the user's selection. UDPRecvProg then sends the request number to the sender and plays the audio file as before. Exercise 21.29What happens if UDPRecvProg's initial 0 byte is lost? How can you modify UDPRecvProg to deal with the possibility of such a loss? What other types of loss are possible? Answer: If the initial 0 byte is lost (or the program listing returned by the sender is lost), UDPRecvProg hangs while waiting for the sender's reply. You can modify UDPRecvProg to time out and retry the initial byte a specified number of times before giving up. Similarly, the request number may be lost. Again, UDPRecvProg should time out and retry a specified number of times. UDPRecvProg should ignore loss of individual audio packets. However, if UDPRecvProg detects that the audio packet loss rate is too high, it should probably inform the user of a problem. 21.4.2 Multiple programs and multiple receiversCopy UDPSendProg.c into UDPSendMult.c and compile it as UDPSendMult. Modify the program to work with multiple copies of the receiver. This modification is similar to changing a serial server into a parallel server. Exercise 21.30How does UDPSendMult behave under Test Case 3 and Test Case 4? Answer: In this implementation the receivers are independent and receive independently generated data streams. One receiver does not affect another. |
[ Team LiB ] |
No comments:
Post a Comment