network library: how to write datas with an array?
in
Core Library Questions
•
2 years ago
Hi!
I a, trying to modify shiffmans multi-user/multi-client exaples ( multi-user, multi-client) with the network library. What I noticed was that, when i use the readString() function, like in the examples, it always crashed down sooner or later.
Than i tried to write the datas separately. I wanna write four datas: mouseX, mouseY, pmouseX and pmouseY (4x "client.write(data);" ). Works well actually, never crashes. But it looks like the other client cant catch them in the correct order, so the lines always jumps.
Now im trying to write the datas with a byte[]. Dont seems to work as well (i am not sure if i set it up right). So my question, what is the best way to write datas with an array?
I a, trying to modify shiffmans multi-user/multi-client exaples ( multi-user, multi-client) with the network library. What I noticed was that, when i use the readString() function, like in the examples, it always crashed down sooner or later.
Than i tried to write the datas separately. I wanna write four datas: mouseX, mouseY, pmouseX and pmouseY (4x "client.write(data);" ). Works well actually, never crashes. But it looks like the other client cant catch them in the correct order, so the lines always jumps.
Now im trying to write the datas with a byte[]. Dont seems to work as well (i am not sure if i set it up right). So my question, what is the best way to write datas with an array?
- // SERVER
- import processing.net.*;
- Server server;
- void setup() {
- size(400,200);
- server = new Server(this, 5204);
- }
- void draw() {
- background(255);
- Client client = server.available();
- if (client != null) {
- byte[] inc = client.readBytes();
- server.write(inc);
- }
- }
- // CLIENT(s)
- import processing.net.*;
- Client client;
- void setup() {
- size(200,200);
- client = new Client(this, "127.0.0.1" , 5204);
- background(255);
- smooth();
- }
- void draw() {
- if (client.available() > 0) {
- byte[] byteC = client.readBytes();
- line(byteC[0],byteC[1],byteC[2],byteC[3]);
- }
- }
- void mouseDragged() {
- byte[] outb = {(byte)mouseX, (byte)mouseY, (byte)pmouseX, (byte)pmouseY};
- client.write(outb);
- }
1