NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: akunkeji on March 25, 2011, 03:44:03 pm



Title: EJS can not access the network?
Post by: akunkeji on March 25, 2011, 03:44:03 pm
EJS can not access the network?
For example, visit the Web site through the HTTP protocol´╝îOr access Ethernet through the TCP/IP protocol.


thanks
 :)


Title: Re: EJS can not access the network?
Post by: Fu-Kwun Hwang on March 25, 2011, 09:02:59 pm
Do you mean access the EJS examples from within the EJS?
May be it is the antivirus software or firewall software restrict the access to the internet from java.
You need to check your setting in your computer.


Title: Re: EJS can not access the network?
Post by: akunkeji on March 26, 2011, 09:34:01 am
I'm so sorry,My expression isn't clear enough. My mean is:
Can EJS generate's Simulation program access the network?


Title: Re: EJS can not access the network?
Post by: Fu-Kwun Hwang on March 26, 2011, 10:57:06 am
There are build in java function which can do the job.
For example:
There is a GUI element in EJS can get image from webcam (if you provide IP of the webcam as property for that GUI element).

Please explain in detail what you want to do.


Title: Re: EJS can not access the network?
Post by: akunkeji on March 26, 2011, 02:27:58 pm
I would like to send a page request to the site, and then receives the returned HTML code from the site.
For example:
Send "http://www.google.com" to the Google website and receive this page's HTML code (not display this page.)


Title: Re: Use webReader GUI element in EJS to send HTTP request
Post by: Fu-Kwun Hwang on March 26, 2011, 03:43:52 pm
A web server reader sends commands to an HTTP web server and reads its response.
Usage:
To add a web server reader element to your model, drag the icon element to the list of your model elements and set the "Server address" field to the base URL of your server or link it to a String model variable (as in %myServerURLString%) that will contain it.

A web server reader element does not connect to the web server until you instruct it to do so (in any suitable part) in your model code.

A call to the element method String readOutput(String _command) will send the _command string appened to the server address and will read teh server's output. This makes it easy to send PHP commands to a given server or read different pages from the same server. The method returns a String with the server response to the command, or null if there was any error in the process.

A call to the element method String getServerAddress() returns the address actually used by the element.

You can also change the server address programmatically, using the method setServerAddress(String _serverAddress) . This sets the server address to a constant String (such as "http://www.um.es") or links it to a String model variable (such as "%myURLStringVariable%") which will need to provide the correct URL value.

Notice that the element will correct the URL of the final command sent to the server. For instance, spaces are replaced by the more correct %20 special character combination. Similarly, 'and' characters (&) are replaced by %26.
Example of use
The following code reads the last version of EJS as indicated in the EJS wiki. (Notice that the call to setServerAddress can be removed by editing the element's properties.)

webReader.setServerAddress("http://www.um.es/fem/EjsWiki");
String responseStr = webReader.readOutput("/Site/EjsCurrentVersion?action=source");
if (responseStr==null) {
  _println("Could not read response from "+webReader.getServerAddress());
  return;
}
_println("EJS current version is " + responseStr);
    


You might want to check out: HTTPclient (http://hc.apache.org/httpcomponents-client-ga/tutorial/html/) if you need more avvanced functions.
You can use it within EJS. However, EJS is not designed to display html page.


Title: Re: EJS can not access the network?
Post by: akunkeji on March 26, 2011, 08:09:47 pm
You answer are very helpful for me.
This is what I need!
Thank you very much!