UDP Communications

In this seminar we’ll look at simple networked communications using UDP sockets.

You’ll need :

The Java programs are supplied as source, so you can compare how I’ve done things in Java to how you might do them. And as a Jar file, run using:

    java -jar <name>.jar
  1. Simple Display
  2. java ui sends control messages
  3. Quote client for java quote server
  4. String Manipulation
  5. Hold on to your seats…
  6. Report state of Switches
  7. Data logging and graphing utility

Simple Display

You will need two sets of code.

  1. The MBED code s7.1
  2. The Java code s7.1.a

Compile and run both:

Take some time to look through the code for each, identify

Can messages be sent to any board?

java ui sends control messages

You will need two sets of code.

  1. The MBED code s7.2
  2. The Java code s7.2.a

Compile and run both:

Take some time to look through the code for each, identify

How might you extend the capabilities to control all the LEDs on the MBED board and the Application shield?

Think about the names used as keys

Quote client for java quote server

The Java Tutorials have an example quote server .

The Program in s7.3 has a client that gets a quote from the server and displays it.

The version of the Server in s7.3.a is the version from the Tutorial, with some additional print statements to show the connection details.

String Manipulation

In all the cases shown, the Datagram messages are blocks of formatted text. A frequently used format is.

Review the string manipulation features of C and Java.

How would you use these in each language to:

Hold on to your seats…

We now hit regions (“here be dragons”) where we end up having to use multiple Threads.

  1. In both the MBED C libraries and the Java JDK UDP communications is blocking.
    We need a thread just to handle the communications.
  2. In Java, swing has it’s own threads if we want to update the display from code (ugh!)
  3. In the C code we have to have a thread to poll sensors that cannot genrate events.

Report state of Switches

This Pair of programs monitors the state of the switches, communicates this to the Java program that displays them as a set of Radio Buttons.

  1. Look at the console/monitor output from both. Why is there so much traffic?
  2. Comment out the line in the MBED program
     eventqueue.call_every(500,jspoll);
    

    What happens to the traffic?

  3. How would you rewrite the polling function to send messages on change of state rather than sending the current state?

Data logging and graphing utility

There is lots of complexity here, managing threads data, messaging, sensor polling, and display updates.

There are several techniques I’ve used, in managing the complexity of the code. How would you manage the system? What changes and improvements can you suggest over my code?


© 2017   Dr Alun Moon
alun.moon@northumbria.ac.uk