ZiBaT => Peter Levinsky => Tech => exercise
Introduction
Simple UDP Socket - JSON
Updated : 2018-09-04

Simple UDP Socket - XML & JSON

Mission:

To design and program two projects one to be a Sender and one to be a Receiver.
From the Sender to the Receiver you are to sent information as A) plain text and B) json encoded.

Background:

Previous exercises Simple (tcp) Sockets

Assignment A: Plain Text communication

  1. In Visual Studio 2015/2017   Create a new solution 'ConsoleApp (.Net Core)', and name it e.g. 'PlainUDPReceiver'.
  2. Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'PlainUDPSender'.
  3. Create a new Project 'Class Libray (.Net Core)' 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 PlainUDPReceiver Create a class 'UDPReceiver' with a method 'Start'.
    1. In the start method
      1. Receive port 11001 (or pick your own port)
      2. When a Datagram is received - read from the Datagram a text string representing a car and print it out.
      3. Can you have two UdpListener listen on port 11001 at the same time?
      4. Can you have a TcpListener listen on port 11001 and a UDPClient listen on port 11001 at the same time?
  6. In the PlainUDPSender Create a class 'UDPSender' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, red, EL23400'
      2. On the socket send a Datagram of the car object in plain text e.g. using the ToString-method (i.e. Not as XML NOR Json)
  7. Run the UDPREceiver and the UDPSender - and see the result
  8. Commit and push your server-solution to a Git-Repository.

Assignment B: Json Communication

  1. Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonUDPReceiver'.
  2. Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonUDPSender'.
  3. In the JsonUDPReceiver Create a class 'UDPReceiver' with a method 'Start'.
    1. In the start method
      1. Listen on port 11002 (or pick your own port number)
      2. When a Datagram is received - read from the Datagram a text string(Json) of the car and print it out.
      3. Decode the Json-string into a car object and print out the car-object (use NewtonSoft nuget-package).
  4. In the JsonUDPSender 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. On the socket send a json-string i.e. Serialize the car object to a json-string and sent it as a Datagram (use NewtonSoft nuget-package).
  5. Run the server and the client - and see the result.
  6. Commit and push your server-solution to a Git-Repository.

Assignment C:  Broadcast messages

  1. Switch your network to use MGV2-DMU1 (MGV2-DMU2) - password = 'lanmagle'
  2. Modify your UDPSender to use a braodcast IP address i.e. new IPEndPoint( IPAddress.Broadcast, PORT-Number ).
  3. Start your UDPReceiver and see the result
  4. Make your neighbor start a UDPReceiver on the same port - can (s)he see the result ?

Assignment D:  More Broadcast messages

  1. Still be at the MGV2-DMUx network.
  2. Make a UDPSender which broadcast out your name to port 11111.
  3. Make a UDPReceiver to collect all names in the class ie. receive a datagram and print out the name.
  4. Extra keep track at the names displayed so each name only is displayed once

 

Extra Assignment:  Chat Service

  1. Back ground: see tcpChatServer
  2. Make the chat server / client to use UDP-server