Zealand => Peter Levinsky => Tech => exercise
More TCP programming Server - Client
Updated : 2019-08-26

More TCP Programming Server - Client

Mission:

To design and program two programs one to be a server the other a client with a protocol in between.
Again NO UWP APP-application.

Background:

The previous exercise Simple Server + Concurrent Server

Domain Description:

The two programs are to use a simple protocol for math (later some timestamps).

E.g.

Assignment A: Client sends 'Add 5 8' as a string -> Server respond 'Result 13'.

Assignment B: Client sends 'Add 5,2 8,4' as a string -> Server respond 'Result 13,6'.

Assignment C: Client sends 'Timestamp&2019-09-03 14:23' as a string -> Server respond 'Valid' or 'Not valid'

Assignment A: Simple math

  1. Make a server - of course cuncurrent working on port 3001..
     
  2. When receiving the request from client (i.e. en DoClient):
    1. Read the line from client
    2. split the string (Hint: use str.Split(' '))
    3. Parse the second and third part into two integers (Hint: use int32.Parse(str))
    4. add the two integers, send back the result.
       
  3. Make a client that can send a request and read the result.
     
  4. Commit and push your server-solution to a Git-Repository
     
  5. Extra: Extend to handle SUB, MUL and DIV as well

    .

Assignment B: More Math now with decimal Numbers

  1. Like in Assignment A make a server - this time on port 3002.
     
  2. Like in Assignment A split the request into three parts.
    This time when parsing you need to specify if you expecting a dot '.' or a comma ',' as a decimal seperator

    If comma use:
    double.Parse(str, new CultureInfo("da-DK"))

    if dot use
    double.Parse(str, new CultureInfo("en-UK"))

    The rest is the same as in assignmet A.

  3. The client is allmost the same except for the port number.
     
  4. Commit your project.
     
  5. Extra: Extend to handle SUB, MUL and DIV as well

 

 

Assignment C: How to handle DataTime

  1. Make a server - this time on port 3003.
     
  2. When receiving the request from client (i.e. en DoClient):
    1. Read the line from client
       
    2. split the string (Hint: use str.Split('&')) - note that after timestamp there is a colon ':' insted of just a space ' '.
       
  3. To parse the date and time into a datetime object use this:

    DateTime.ParseExact(dt, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture)

    For more information see https://docs.microsoft.com/en-us/dotnet/api/system.datetime.parseexact?view=netframework-4.8
     
  4. Make a client that can send a request and read the result.
     
  5. Commit your project.
     
  6. Extra: send back a response of format 'date 03/09 2019 time 14:23'