More Server - An Echo Server Concurrent
Mission:
To design and program two programs one to be a server that is concurrent i.e. can take serveral client even at the same time and then reuse of the client
Again
NO RAZOR PAGE-application.
Background:
The simple echo server from previous exercise Simple Server
For programming en iterative server (concurrent) in C# Console Application (.Net 5)
Assignment A: Refactor Your Echo Server to handle more than one client
- In previous exercise you have implemented a simple Echo server, that takes one connection, handle the client and then close down.
- Now insert a loop to handle several clients i.e. make a while(true) loop after the TcpListener has been started and before you accept the
incomming TcpClient.
- In the loop
call the DoClient method from assignment B in the SimpleServer exercise
- Try your refactored server with SocketTest - can you
start more client consecutive
?
- Optional: Commit and push your server-solution to a Git-Repository.
Assignment B: Refactor Your Server To Handle more client in parallel
-
Refactor your server so all the client will be handled simultaneously.
- Instead of calling the DoClient directly make a Task which runs the DoClient method. The call should be like:
Task.Run(() =>
{
TcpClient tempSocket = socket;
DoClient(tempSocket);
});
.
- Try your refactored server with SocketTest. Start two versions of SocketTest - can you
call the server at the same time (nearly the same time)?
To see a difference insert the code line Thread.Sleep(5000);
in the DoClient before returning the echoLine.
- Optional: Commit your project.