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
- In Visual Studio 2015/2017 Create a new solution 'ConsoleApp (.Net Core)', and name it e.g. 'PlainUDPReceiver'.
- Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'PlainUDPSender'.
- Create a new Project 'Class Libray (.Net Core)' and name it e.g. 'ModelLib'.
- In the ModelLib create one model classes
- a 'Car' with the properties 'model, color, registration number'
- In the PlainUDPReceiver Create a class 'UDPReceiver' with a method 'Start'.
- In the start method
- Receive port 11001 (or pick your own port)
- When a Datagram is received - read from the Datagram a text string representing a car and print it out.
- Can you have two UdpListener listen on port 11001 at the same time?
- Can you have a TcpListener listen on port 11001 and a UDPClient listen on port 11001 at the same time?
- In the PlainUDPSender Create a class 'UDPSender' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, red, EL23400'
- 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)
- Run the UDPREceiver and the UDPSender - 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. 'JsonUDPReceiver'.
- Create a new Project 'ConsoleApp (.Net Core)', and name it e.g. 'JsonUDPSender'.
- In the JsonUDPReceiver Create a class 'UDPReceiver' with a method 'Start'.
- In the start method
- Listen on port 11002 (or pick your own port number)
- When a Datagram is received - read from the Datagram a text string(Json) of the car and print it out.
- Decode the Json-string into a car object and print out the car-object (use NewtonSoft nuget-package).
- In the JsonUDPSender Create a class 'Client' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, Green, JsonCar4'
- 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).
- Run the server and the client - and see the result.
- Commit and push
your
server-solution to a Git-Repository.
Assignment C: Broadcast messages
- Switch your network to use MGV2-DMU1 (MGV2-DMU2) - password = 'lanmagle'
- Modify your UDPSender to use a braodcast IP address i.e. new IPEndPoint( IPAddress.Broadcast, PORT-Number ).
- Start your UDPReceiver and see the result
- Make your neighbor start a UDPReceiver on the same port - can (s)he see the result ?
Assignment D: More Broadcast messages
- Still be at the MGV2-DMUx network.
- Make a UDPSender which broadcast out your name to port 11111.
- Make a UDPReceiver to collect all names in the class ie. receive a datagram and print out the name.
- Extra keep track at the names displayed so each name only is displayed once
Extra Assignment: Chat Service
- Back ground: see tcpChatServer
- Make the chat server / client to use UDP-server