UDP protocol

edited April 2015 in Library Questions

Hi

I've create a UDP server in a raspberry and with an array I send the state of my interruptor "1"or"0" but how to receive this array in processing ?

after my programme need to go in android mode

thanks

Tagged:

Answers

  • Have you searched UDP in the libraries page?

  • I've find this code

    void receive( byte[] data ) { // <-- extended handler

    println("recu !!"); for (int i=0;i<data.length;i++) print(data[i]); println(); if (data[i]==10000000) println(allumer); }

    i receive a binary code in 8 bytes and when i compile my programme i have an error "can not find anything named i" for the line if (data[i]==10000000)

  • edited April 2015

    The variable i is defined only for the loop. When the loop ends, the variable "disappears". Even if was still visible, it would have the value of data.length, so it would throw an ArrayIndexOutOfBoundsException...

    You can replace this line with:

    if (data[data.length - 1]==10000000) println(allumer);
    
Sign In or Register to comment.