Ethernet Communications Overview

Written by Anthony Pavia on Sep 13, 2022 1:14 pm

JNIORs can connect with other devices via Ethernet connections. Defining a port and IP, the JNIOR can listen or send to a device with those Ethernet settings using the IO and Net classes of the JANOS Runtime library. Receiving data uses a DataInputStream and sending data uses a DataOutputStream. 

TCP

Below is a very short example, that shows a quick reference to the IO class to create a socket to open a DataOutputStream. Once that is open I can send a message to an external device. The socket only requires the IP address and the port number. In this example the IP is 10.0.0.17 and the port is 9222. Once the DataOutputStream is created using the socket, I send a string out it. I use a TCP server I created that listens on that IP and port number to see if it receives the data sent.

View on GitHub

I put the built jar file of this example application into the JNIOR’s flash folder and ran it from the Web UI’s console tab. After it has successfully run, I check my TCP server and see that the information was successfully received.

UDP

Another example of Ethernet control uses a UDP connection versus a TCP connection. Another example is below, using the Datagram Socket and Packet classes from the Java.net package. This creates a UDP connection from the JNIOR to any UDP server listening and sends it a string. 

View on GitHub

Just like before, I put the built jar file of this example application into the JNIOR’s flash folder and ran it from the Web UI’s console tab. After it has successfully run, I check a UDP server I created  and see that the information was successfully received.

On this page