Server that gets image stream from spout and send it to client

hello all, i try to get a texture from spout and send it thought server and client, the data flow seems working but i can reconvert the bytes into an image

the scripts are here

server with spout:

import java.nio.ByteBuffer;
import spout.;
import processing.net.
;

Server s;
Client c;
String input;
int data;
PGraphics pgr; // Canvas to receive a texture
PImage img; // Image to receive a texture

Spout spout;

void setup() {

// Initial window size
size(640, 360, P3D);

surface.setResizable(true);

// Create a canvas or an image to receive the data.
pgr = createGraphics(width, height, PConstants.P2D);
img = createImage(width, height, ARGB);

// Graphics and image objects can be created
// at any size, but their dimensions are changed
// to match the sender that the receiver connects to.

// CREATE A NEW SPOUT OBJECT
spout = new Spout(this);
s = new Server(this, 12345);
// OPTION : CREATE A NAMED SPOUT RECEIVER
//
// By default, the active sender will be detected
// when receiveTexture is called. But you can specify
// the name of the sender to initially connect to.
// spout.createReceiver(“Spout DX11 Sender”);
}

void draw() {

background(0);

//
// RECEIVE A SHARED TEXTURE
//

// OPTION 1: Receive and draw the texture
//spout.receiveTexture();

// OPTION 2: Receive into PGraphics texture
// pgr = spout.receiveTexture(pgr);
// image(pgr, 0, 0, width, height);

// OPTION 3: Receive into PImage texture
img = spout.receiveTexture(img);
image(img, 0, 0, width, height);

byte array = convertImageToByteArray(img);
s.write(array);
print(array);
// OPTION 4: Receive into PImage pixels
// img = spout.receivePixels(img);
// image(img, 0, 0, width, height);

// Optionally resize the window to match the sender
// spout.resizeFrame();
}

// SELECT A SPOUT SENDER
void mousePressed() {
// RH click to select a sender
if (mouseButton == RIGHT) {
// Bring up a dialog to select a sender.
// Spout installation required
spout.selectSender();
}
}

byte convertImageToByteArray(PImage img) {
img.loadPixels();
int px = img.pixels;
ByteBuffer bb = ByteBuffer.allocate((2 + px.length) * 4);
bb.putInt(img.width);
bb.putInt(img.height);
for (int d : px) {
bb.putInt(d);
}
return bb.array();
}

client to receive

import processing.net.*;
import java.nio.ByteBuffer;
Client c;

int data;

void setup() {
size(640, 360,P3D);

// Slow it down a little
// Connect to the server’s IP address and port­
c = new Client(this, “127.0.0.1”, 12345); // Replace with your server’s IP and port
}

void draw() {

// Receive data from server
if (c.available() > 0) {
byte input = c.readBytes();
////input = input.substring(0, input.indexOf(“\n”)); // Only up to the newline
//input = input.substring(0,input.indexOf(“\n”)); // Only up to the newline
//data = int(split(input, ’ '));
// Split values into an array

PImage imgNew = convertByteArrayToImage(input);
//text("Byte array > image", 220, 16);
image(imgNew, 0, 0);

}
}

PImage convertByteArrayToImage(byte bytes) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
int w = bb.getInt();
int h = bb.getInt();
PImage img = new PImage(w, h);
int px = img.pixels;
for (int i = 0; i < px.length; i++) {
px[i] = bb.getInt();
}
img.updatePixels();
return img;
}

I haven’t run your code but I’m not sure if you update the img.pixels() array at the very bottom, inside your convertByteArrayToImage().

I’m a bit rusty on java refs though so

Oh also, can you clarify: are you getting errors, runtime errors, a black screen? Whats the specific error?