ProcessingJS and using Network library (Client class) to load external web page

edited December 2017 in JavaScript Mode

Hi,

I'm porting my processing app to processingJS so it can be used from any device like a smartphone. My app downloads/scrapes info from a external webpage. With the processing app, the following code works:

import processing.net.*; 
Client myClient;
String IPaddressString = "www.processing.org";//processing

void setup(){
  String dataIn;
  try{
    myClient = new Client(this, IPaddressString, 80);
    myClient.write("GET / HTTP/1.1\r\n");
    myClient.write("Host: www.processing.org\r\n"); // Be polite and say who we are
    myClient.write("Host: 192.168.0.15\r\n"); // Be polite and say who we are
    myClient.write("User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7\r\n");
    myClient.write("Accept: text/html,application/xhtml+xml,application/xml\r\n");
    myClient.write("Accept-Language: en-us,en;q=0.5\r\n");
    myClient.write("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
    myClient.write("\r\n");
  }catch(Exception e){
    println(e.toString());
    println(e.getMessage());
  }
}

void draw(){
  String dataIn;
  try{
    if (myClient.available()>0) {
        dataIn = myClient.readString();
        println(dataIn);
    }
  }catch(Exception e){
    println(e.toString());
    println(e.getMessage());
  } 
}

In processingJS, I get the error "ReferenceError: Client is not defined".

In my search I cannot find anything, does anyone have an idea?

thx, Nard

Tagged:

Answers

  • Also investigated security settings in the processingJS sketch by using IPaddressString="localhost", but same message. Also tried chrome/firefox/ie with page containing sketch accessed as local file and via a webserver (mongoose) All options give the same error message.

  • Answer ✓
    • Client is a class belonging to a Java library. Therefore it can't be used in JavaScript! [-X
    • You're gonna need to find a JS library w/ similar capabilities I'm afraid! :-S
  • In JS, perhaps you can load the page in an iframe.

  • Thx.

    Based on your answers I tried iframes, but I then encountered the problem of javascript security which prevents cross domain data exchange.

    I now made a simple webbrowser in VB.Net which provided the functionality I need: The browser loads a webpage with the processing sketch. From within processing I call a javascript function on the webpage which signals VB.Net to load another webpage and return the info via javascript to processing. The guide from Pomax at processingjs.org provided a lot of insight! (But turned out to be quite easy.)

Sign In or Register to comment.