Solved

Evaluate of a return Message in Java

Posted on 1997-11-19
2
153 Views
Last Modified: 2012-05-04
When I input the URL http://cameraname/io/relayon.txt in a Browser, I can switch on the relay in a camera web server. The server then gives the back the Message Relay is on that I can see in the Browser. My question is, how can I evaluate  
this Message in Java? Maybe with InputStream or DataInputStream or FileInputStream or otherwise?
I've tried it like this, but it does not work:

URL urlOpen = new URL(http://cameraname/io/relayon.txt);
URLConnection connect = urlOpen.openConnection();
connect.setDefaultAllowUserInteraction( true);
connect.setUseCaches( false );      
connect.setDoInput( true );            
connect.setDoOutput( false );       
connect.connect();

DataInputStream inputstream = new DataInputStream( connect.getInputStream()      );
                  
while( (String s=inputstream.readLine()) != null );
{
      // do whatever you want to do with s
}
inputstream.close();

Thanks, Mike
0
Comment
Question by:mkaufman
2 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 20 total points
ID: 1230935

You were close:

DataInputStream dis;

URL urlOpen = new URL(http://cameraname/io/relayon.txt);

dis = new DataInputStream(urlOpen.openStream());

String s;

while ((s = dis.readLine()) != null) {
  System.out.println(s);
  //Or whatever it is you do :)
}
0
 

Author Comment

by:mkaufman
ID: 1230936
I've tried it but it does not work.
The String s is always empty. Have I maybe to wait a moment to the answer from the server?
Then I could wait for it in a Thread.

Thank Mike

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question