Problem with send hex data from TCP/IP

Hi all there! Can you help me please understand how i can send the hex data pattern to remote device ip ike 10.0.255.182 and port 8234?
i try use that code

import processing.net.*;
Client c1;
byte[] dataIn ={};
int flag =0;
byte[] request = {0xA5, 0xC3, 0x3C, 0x5A, 0xFF, 0x63, 0x0C, 0x01, 0x01, 0xEE};

void setup() {
  size(1000, 900);
  c1 = new Client(this, "10.0.255.182", 8234);
}
void draw() {
  background(0);
      c1.write(request);
      delay(500);
}

void clientEvent(Client someClient) {
  dataIn = someClient.read();
  println(dataIn);
  redraw();
  }

But processing write me - cannot convert int to byte.
Threre is example, that i need
2022-05-06_16-03-41

1 Like

You can use the Java ByteBuffer class to convert any primitive type to an array of bytes, then send it over the network. You can also use ByteBuffer to convert an array of bytes to any primitive. Another thing to note is that the ByteBuffer has as option for byte order, which allows you to change the endianness of the stored data. Depending on the device that is receiving the data, you may need to change that option to something specific, rather than the default.

1 Like
byte[] request = byte(new int[] {
  0xA5, 0xC3, 0x3C, 0x5A, 0xFF, 0x63, 0x0C, 0x01, 0x01, 0xEE
});
2 Likes

Hello @demoss,

See integer literals:

Related discussions:

:)

2 Likes

Thank you very much for your help!

1 Like

Hello @demoss,

What is the name of this application that you used?

From your previous post:

2022-05-06_16-03-41

I have very similar tools but have not seen this one.

:)

1 Like

@demoss

Hello. Nice to meet you.
Have you ever solved the above problem?