Creating a basic online service

Hi, I’m trying to make a online application.

I have a hosting server, where I can put a Java file on it, but I don’t know how I could translate a processing sketch to java.

I know how to create a basic Server & Client setup, but I don’t wanna host it on my home network.

Help is appreciated! :slight_smile:

1 Like

Are you using the Processing Network library? If so, you could just run a Processing sketch with a Server instance–no translation needed. I’ve tinkered a bit with this setup on a Debian server and might be able to help.

Hi @nuhuhwy

What exactly does that mean for you … :slight_smile:

  • … A RESTapi which acts as a service ?
  • … A GUI where users can interact with ?
  • … Both from above ?

Cheers
— mnse

1 Like

Something where users are able to send messages to and get messages.

How about testing a client/server setup to get started?

This example just streams random data from a server to all connected clients. It’s a remix of advice I found here. I used Google Compute Engine to spin up a server running Debian Bullseye.

Server setup

# Install required packages.
sudo apt update
sudo apt install wget xvfb libxrender1 libxtst6 libxi6 default-jdk
# Download and install Processing.
wget https://github.com/processing/processing4/releases/download/processing-1292-4.2/processing-4.2-linux-x64.tgz
tar xzf processing-4.2-linux-x64.tgz
cd processing-4.2
./install.sh
# Create the demo sketch.
cd ..
mkdir server_demo
# Add starter code to server_demo.pde.
vi server_demo/server_demo.pde
# Run server.
sudo xvfb-run ./processing-4.2/processing-java --sketch=server_demo --run

server_demo.pde

// Server in cloud.
import processing.net.*;

Server myServer;

void setup() {
  myServer = new Server(this, 80, "0.0.0.0");
}

void draw() {
  if (frameCount % 60 == 0) {
    int x = int(random(50, 150));
    int y = int(random(50, 150));
    String dataOut = x + "," + y;
    myServer.write(dataOut); 
  }
}

client_demo.pde

// Client on laptop.
import processing.net.*; 

Client myClient; 
int x, y;
 
void setup() { 
  size(200, 200); 
  // 12.345.678.90 is a placeholder for the server's IP address.
  myClient = new Client(this, "12.345.678.90", 80); 
}

void draw() {
  background(0);
  if (myClient.available() > 0) { 
    String dataIn = myClient.readString();
    String[] position = dataIn.split(",");
    x = int(position[0]);
    y = int(position[1]);
  }
  fill(255, 0, 0);
  circle(x, y, 50);
}
2 Likes

You are the best! You gave me a full step tutorial for all i need to do practiacally!
Thanks!

1 Like