Simple Server - An Echo Server
Mission:
To design and program two projects one to be a server and one to be a client.
From the client to the server you are to sent information as plain text and json encoded.
Background:
Previous exercises simple socket + concurrent socket
For Json
Assignment A: Plain Text communication
- In Visual Studio 2015/2017 Create a new solution 'ConsoleApp (.Net Core)', and name it e.g. 'PlainServer'.
- Create a new Project 'ConsoleApp (.Net 5)', and name it e.g. 'PlainClient'.
- Create a new Project 'Class Libray (.Net 5)' and name it e.g. 'ModelLib'.
- In the ModelLib create one model classes
- a 'Car' with the properties 'model, color, registration number'
- In the PlainServer Create a class 'Server' with a method 'Start'.
- In the start method
- Listen on port 10001
- When a client connect - read from the socket a text string representing a car and print it out.
- Extra: decode the string into a car object and print out the car-object.
- In the PlainClient Create a class 'Client' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, red, EL23400'
- Connect to the server port 10001
- When connected - print to the socket the car object in plain text e.g. using the ToString-method (i.e. Not as XML NOR Json)
- Run the server and the client - and see the result
- Commit and push
your
server-solution to a Git-Repository.
Assignment B: Json Communication
- Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonServer'.
- Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonClient'.
- In the JsonServer Create a class 'Server' with a method 'Start'.
- In the start method
- Listen on port 10002
- When a client connect - read from the socket a text string(json) representing a car and print it out.
- Decode the json-string into a car object and print out the car-object.(use JsonSerializer.Deserialize<Car>(<<string>>);)
- In the JsonClient Create a class 'Client' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, Green, JsonCar4'
- Connect to the server port 10002
- When connected - Serialize the car object to a json-string (JsonSerializer.Serialize(car)), which is printet/sent to the socket.
- Run the server and the client - and see the result.
- Commit and push
your
server-solution to a Git-Repository.
Assignment Extra: use More Complex object-Structure
- In the ModelLib add a new class:
- a 'AutoSale' with the properties 'name, address, cars (a list)',
- For the plain text, xml and for the json, now send a car-dealer with at least two cars over the network.
Assignment Extra: Encode with XML
Background For xml:
Steps:
- Create a new Project 'ConsoleApp (.Net 5)', and name it e.g. 'XmlServer'.
- Create a new Project 'ConsoleApp (.Net 5)', and name it e.g. 'XmlClient'.
- In the XmlServer Create a class 'Server' with a method 'Start'.
- In the start method
- Listen on port 20001
- When a client connect - read from the socket a text string(xml) representing a car and print it out.
- Decode the xml-string into a car object and print out the car-object.
- In the XmlClient Create a class 'Client' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, Blue, XMLCar23'
- Connect to the server port 20001
- When connected - Serialize the car object to a xml-string , which is printet/sent to the socket.
- Run the server and the client - and see the result.
- Commit and push
your
server-solution to a Git-Repository.