/* * toggles IO3 of the siteplayer using UDP * */ import java.net.*; import java.util.*; import java.io.*; import java.text.*; public class Toggle_udp { static final int PORT = 26482; DatagramSocket ds = null; boolean keepRunning = true; public static void main(String[] args) { Toggle_udp toggle = new Toggle_udp(); toggle.startServing(); } public Toggle_udp() { try { ds = new DatagramSocket(PORT); } catch (SocketException exp) {} } public void startServing() { InetAddress address = null; try { address = InetAddress.getByName("siteplayer"); // this resolves to 192.168.0.17 } catch (UnknownHostException uhe) {} byte[] dataBuffer1 = new byte[7]; DatagramPacket dpsend = new DatagramPacket(dataBuffer1, dataBuffer1.length, address, PORT); dataBuffer1[0] = 0x01; // number of bytes to send dataBuffer1[1] = (byte) 0xFE; // compliment of number of bytes to send dataBuffer1[2] = 0x14; // low byte of address of IO3 dataBuffer1[3] = (byte) 0xFF; // high byte of address of IO3 dataBuffer1[5] = 0x00; // udp must end with two zero bytes dataBuffer1[6] = 0x00; while(keepRunning) { try { dataBuffer1[4] = 0x00; // turn on led ds.send(dpsend); try { Thread.sleep(1000); } catch (InterruptedException interrupted) {} dataBuffer1[4] = 0x01; // turn off led ds.send(dpsend); try { Thread.sleep(1000); } catch (InterruptedException interrupted) {} } catch (IOException expe) {} } } }