I have two clients A, B
also I have a server S
A sends a request to the server S, due to this request the server S wants to inform client B that client A made a request.
the same can happen if B sends a request to server S but this time server S will inform A
is this possible with the client server model? I have managed to create a simple program where client A sends a request to server S and displays the server’s response. In this program server S listens to endless connections which means that I have something like this:
while(true){
Socket userSocket = serverSocket.accept();
new Connection(clientSocket);
//where in the Connection class we manage the connection events
}
but I can’t understand how I can make the server ‘S’ a client inside the class “Connection” to the client that didn’t send the request. If I do the same process I usually do for any client (A or B) I get an exception which prints some IP address and I’m not sure which ones because I run everything locally.
thanks in advance
Practically speaking you can do what you said, which is to have S notify B that A has made a request or vice versa. Conceptually though this doesn’t mean that S is now a client of B. S is still a server it just happens to be sending B a message on its own rather than reacting to input from B.
Think about S representing a chat server. If A sends a message to S and S forwards it to B, is S now a client of B or still a server?