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
- 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)
- Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'PlainUDPSender'.
- Create a new Project 'Class Libray (.Net Framework)' 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 TcpListener 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 Datagrm 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: XML Communication
- Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'XmlUDPReceiver'.
- Create a new Project 'ConsoleApp (.Net Framework)', and name it e.g. 'XmlUDPSender'.
- In the XmlUDPReceiver 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(xml) of the car and print it out.
- Decode the xml-string into a car object and print out the car-object.
- In the XmlUDPSender Create a class 'UDPSender' with a method 'Start'.
- In the start method
- make an object of the car class e.g. 'Tesla, Blue, XMLCar23'
- On the socket send a xml-string i.e. Serialize the car object to a xml-string and sent it as a Datagram.
- Run the UDPReceiver and the UDPSender - and see the result.
- Commit and push
your
server-solution to a Git-Repository.
Assignment C: Json Communication
- Create a new Project 'ConsoleApp (.Net framework)', and name it e.g. 'JsonUDPReceiver'.
- Create a new Project 'ConsoleApp (.Net Framework)', and name it e.g. 'JsonUDPSender'.
- In the JsonUDPReceiver Create a class 'UDPReceiver' with a method 'Start'.
- In the start method
- Listen on port 11003 (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..
- Run the server and the client - and see the result.
- Commit and push
your
server-solution to a Git-Repository.
Assignment D: Broadcast messages
- Switch your network to use EGV5-DMU3 - password = 'lanelisa'
- 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 ?