Network module help

Hi! I know this is vage but i have problems using network to get a pastebin post.
I tried this:

import processing.net.*; 

Client myClient; 
int dataIn; 
 
void setup() { 
  size(200, 200);
  myClient = new Client(this, "http://pastebin.com/MyCode", 80); 
} 
 
void draw() { 
  if (myClient.available() > 0) { 
    dataIn = myClient.read(); 
  } 
  print(dataIn); 
} 

But it gives all 0s and an exception.
Thanks!

Welcome! :slight_smile: Could you share what you have tried so far?

You’re more likely to get answers by following some of the tips outlined in this post :point_down:

Thanks a lot!
I improved my question and thanks for the advice :smiley:.

1 Like

If you read the reference code again you will see this:

// Connect to the local machine at port 5204.
 // This example will not run if you haven't
  // previously started a server on this port.
  myClient = new Client(this, "127.0.0.1", 5204);

You have to fire up the Server first using the same port. If you use the Reference example for Server and run that code first then fire up the Client example you should see numbers other than all zeroes. Not sure how you would connect to Pastebin.

Run these two apps at the same time starting with the Server.

Server:

import processing.net.*;

Server myServer;
byte outputValue = 0;

void setup() {
  size(200, 200);
  myServer = new Server(this, 5204); 
}

void draw() {
  outputValue += 4;
  myServer.write(outputValue);
}

Client:

import processing.net.*;

Client myClient;
int dataIn;

void setup() {
  size(200, 200);
  myClient = new Client(this, "127.0.0.1", 5204);
}

void draw() {
  if (myClient.available() > 0) {
    dataIn = myClient.read();
    println(dataIn);
  }
}

Hello,

These Network examples come with Processing and work as is for me (last two “Shared” ones) on the same PC:

image

I can also modify them to work on different PCs on my network.
I recall also getting this to work from home to work if I setup my router correctly.

You need to read descriptions for each before using.

Reference:
https://processing.org/tutorials/network

:)

1 Like