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 Razor Pages-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
- Make a server - of course cuncurrent working on port 3001..
- When receiving the request from client (i.e. en DoClient):
- Read the line from client
- split the string (Hint: use str.Split(' '))
- Parse the second and third part into two integers (Hint: use int32.Parse(str))
- add the two integers, send back the result.
- Make a client that can send a request and read the result.
- Commit and push your server-solution to a Git-Repository
- Extra: Extend to handle SUB, MUL and DIV as well
.
Assignment B: More Math now with decimal Numbers
- Like in Assignment A make a server - this time on port 3002.
- 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.
- The client is allmost the same except for the port number.
- Commit your project.
- Extra: Extend to handle SUB, MUL and DIV as well
Assignment C: How to handle DataTime
- Make a server - this time on port 3003.
- When receiving the request from client (i.e. en DoClient):
- Read the line from client
- split the string (Hint: use str.Split('&')) - note that after timestamp there is a colon ':' insted of just a space ' '.
- 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
- Make a client that can send a request and read the result.
- Commit your project.
- Extra: send back a response of format 'date 03/09 2019 time 14:23'