Zealand => Peter Levinsky => Tech => exercise
Introduction
Simple Server - Echo Server - Concurrent
Updated : 2019-08-26

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 UWP APP-application.

Background:

The simple echo server from previous exercise Simple Server

For programming en iterative server (concurrent) in C# Console Application (.Net Core)

Assignment A: Refactor Your Echo Server to handle more than one client

  1. In previous exercise you have implemented a simple Echo server, that takes one connection, handle the client and then close down.
     
  2. 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.
     
  3. In the loop call the DoClient method from assignment B in the SimpleServer exercise
     
  4. Try your refactored server with SocketTest - can you start more client consecutive ?
     
  5. Commit and push your server-solution to a Git-Repository.

Assignment B: Refactor Your Server To Handle more client in parallel

  1. Refactor your server so all the client will be handled simultaneously.
     
  2. 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);
    });

    .
  3. 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.
     
  4. Commit your project.