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

Simple UDP Socket - 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: JSON communication

  1. In Visual Studio 2019   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. 'JsonUDPReceiver'.
  3. Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonUDPSender'.

  4. In the JsonUDPSender Create a class 'UDPSender' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, Green, JsonCar4' -- see / reuse model class from Simple (tcp) Sockets with JSON
      2. On the socket send a json-string i.e. Serialize the car object to a json-string and sent it as a Datagram.

  5. 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.
  1. Run the sender and the receiver - and see the result.
  2. Commit and push your server-solution to a Git-Repository.

Assignment B:  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 C:  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