Solved

Evaluate of a return Message in Java

Posted on 1997-11-19
2
149 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now