which --> Welcher Port
time --> Zeit in Sekunden
Code: Alles auswählen
public void PulseRelais(int which, int time) throws Exception {
SetRelais(which, true);
DatagramSocket socket = new DatagramSocket();
// Basic Command
String sentence = "St_off";
sentence += which;
sentence += " "; // Place holder for the time
sentence += myNetControl.getUserName();
sentence += myNetControl.getPassword();
// Merge the time into the command
byte[] sendData = sentence.getBytes();
sendData[7] = (byte)((time >> 8) & 0xFF);
sendData[8] = (byte)(time & 0xFF);
// Send
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, myNetControl.getInetAddress(), myNetControl.getUdpSendPort());
socket.send(sendPacket);
socket.close();
}
Manuel