Question & Answer: Consider the following pseudocode for a chat program, running over a connected socket. This program…..

Consider the following pseudocode for a chat program, running over a connected socket. This program deadlocks. Correct this.

Client Server
Read from socket Read from socket
Print to screen Print to screen
Read from keyboard Read from keyboard
Send message over socket Send message over socket

—————————————————————————–

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Consider the following pseudocode for a chat program, running over a connected socket. This program…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Consider the following pseudocode for a chat program, running over a connected socket. The above program does not allow one to send multiple messages without receiving a message in-between sends. Why not?

Client Server
Read from socket Read from socket
Print to screen Print to screen
Read from keyboard Read from keyboard
Send message over socket Send message over socket

Expert Answer

 

1.Looking at the sequence of operations for client and server, we can see that both client and server are waiting at the socket at the start. As per the sequence,sending to socket can not happen till a read happens from the keyboard. In a way both are waiting at socket and nobody is writing, that will lead to a deadlock.So a correct sequence can be:

Client:
Read from keyboard
Send message over socket
Read from socket
Print to screen’

Server:

Read from socket
Print to screen
Read from keyboard
Print to screen

2. The current sequence of operations at the client side or the server side is of type Receive-send-Receive. It is because the sequece at both the end first wait at the socket to recive and then wait for user input to send.So no one can send mutiple messages without a receive in between.Ofcourse deadlocks should be removed as per the above steps.

Still stressed from student homework?
Get quality assistance from academic writers!