# Creating a basic online service

**URL:** <https://discourse.processing.org/t/creating-a-basic-online-service/42360>\
**Category:** Project Guidance\
**Created:** [July 6, 2023, 9:47pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360 "2023-07-06T21:47:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)\
**Post date:** [July 6, 2023, 9:47pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/1 "2023-07-06T21:47:18Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![mcintyre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mcintyre/32/14561_2.png) [@mcintyre](https://discourse.processing.org/u/mcintyre)\
**Post date:** [July 7, 2023, 12:30pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/2 "2023-07-07T12:30:44Z")

</div>

Are you using the Processing [Network library](https://processing.org/reference/libraries/net/index.html)? 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.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 7, 2023, 3:02pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/3 "2023-07-07T15:02:39Z")

</div>

Hi @nuhuhwy

> [@nuhuhwy](#):
>
> I’m trying to make a online application.

What exactly does that mean for you … 🙂

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

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)\
**Post date:** [July 8, 2023, 10:54pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/4 "2023-07-08T22:54:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mcintyre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mcintyre/32/14561_2.png) [@mcintyre](https://discourse.processing.org/u/mcintyre)\
**Post date:** [July 9, 2023, 9:18pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/5 "2023-07-09T21:18:14Z")

</div>

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](https://github.com/processing/processing/wiki/Running-without-a-Display). I used Google Compute Engine to spin up a server running Debian Bullseye.

**Server setup**

```bash
# 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**

```java
// 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**

```java
// 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);
}

```

---

<div class="post-metadata">

**Author:** ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)\
**Post date:** [July 10, 2023, 3:14pm UTC](https://discourse.processing.org/t/creating-a-basic-online-service/42360/6 "2023-07-10T15:14:42Z")

</div>

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