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

Simple UDP Sockets

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 plain text, xml encoded and 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 framework)', and name it e.g. 'PlainUDPReceiver'.
    (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. 'PlainUDPSender'.
  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 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 TcpListener 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 Datagrm 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: XML Communication

  1. Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'XmlUDPReceiver'.
  2. Create a new Project 'ConsoleApp (.Net Framework)', and name it e.g. 'XmlUDPSender'.
  3. In the XmlUDPReceiver 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(xml) of the car and print it out.
      3. Decode the xml-string into a car object and print out the car-object.
  4. In the XmlUDPSender Create a class 'UDPSender' with a method 'Start'.
    1. In the start method
      1. make an object of the car class e.g. 'Tesla, Blue, XMLCar23'
      2. On the socket send a xml-string i.e. Serialize the car object to a xml-string and sent it as a Datagram.
  5. Run the UDPReceiver and the UDPSender - 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. 'JsonUDPReceiver'.
  2. Create a new Project 'ConsoleApp (.Net Framework)', 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 11003 (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..
  5. Run the server and the client - and see the result.
  6. Commit and push your server-solution to a Git-Repository.

Assignment D:  Broadcast messages

  1. Switch your network to use EGV5-DMU3 - password = 'lanelisa'
  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 ?