ZiBaT => Peter Levinsky => Tech => exercise
Introduction
Simple Socket - XML & JSON
Updated : 2017-08-26

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, xml encoded and json encoded.

Background:

Previous exercises simple socket + concurrent socket

For xml:
For Json

Assignment A: Plain Text communication

  1. In Visual Studio 2015/2017   Create a new solution 'ConsoleApp (.Net framework)', and name it e.g. 'PlainServer'.
    (NB! in 2017 do NOT choose 'ConsoleApp .Net Core', which have restricted API's)
  2. Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'PlainClient'.
  3. Create a new Project 'Class Libray (.Net Framework)' and name it e.g. 'ModelLib'.
  4. In the ModelLib create one model classes
    1. a 'Car' with the properties 'model, color, registration number'
  5. In the PlainServer Create a class 'Server' with a method 'Start'.
    1. In the start method
      1. Listen on port 10001
      2. When a client connect - read from the socket a text string representing a car and print it out.
      3. Extra: decode the string into a car object and print out the car-object.
  6. In the PlainClient Create a class 'Client' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, red, EL23400'
      2. Connect to the server port 10001
      3. 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)
  7. Run the server and the client - and see the result
  8. Commit and push your server-solution to a Git-Repository.

Assignment B: XML Communication

  1. Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'XmlServer'.
  2. Create a new Project 'ConsoleApp (.Net Framework)', and name it e.g. 'XmlClient'.
  3. In the XmlServer Create a class 'Server' with a method 'Start'.
    1. In the start method
      1. Listen on port 10002
      2. When a client connect - read from the socket a text string(xml) representing a car and print it out.
      3. Decode the xml-string into a car object and print out the car-object.
  4. In the XmlClient Create a class 'Client' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, Blue, XMLCar23'
      2. Connect to the server port 10002
      3. When connected - Serialize the car object to a xml-string , which is printet/sent to the socket.
  5. Run the server and the client - and see the result.
  6. Commit and push your server-solution to a Git-Repository.

Assignment C: Json Communication

  1. Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'JsonServer'.
  2. Create a new Project 'ConsoleApp (.Net Framework)', and name it e.g. 'JsonClient'.
  3. In the JsonServer Create a class 'Server' with a method 'Start'.
    1. In the start method
      1. Listen on port 10003
      2. When a client connect - read from the socket a text string(json) representing a car and print it out.
      3. Decode the json-string into a car object and print out the car-object.(use Newtonsoft:JsonConvert)
  4. In the JsonClient Create a class 'Client' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, Green, JsonCar4'
      2. Connect to the server port 10003
      3. When connected - Serialize the car object to a json-string , which is printet/sent to the socket.
  5. Run the server and the client - and see the result.
  6. Commit and push your server-solution to a Git-Repository.

Assignment Extra A:  use More Complex object-Structure

  1. In the ModelLib add a new class:
    1. a 'Car Dealer' with the properties 'name, address, cars (a list)',
  2. For the plain text, xml and for the json, now send a car-dealer with at least two cars over the network.