Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following pseudocode for a chat program, running over a connected s

ID: 3867675 • Letter: C

Question

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

-----------------------------------------------------------------------------

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

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

Explanation / 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.