Solved

URL Connection

Posted on 1997-11-14
3
166 Views
Last Modified: 2010-04-16
I am a student and I'm engaged with the dissertation at the moment.The actually problem of my work is the following:
A web-server camera is installed local over a Hub with a PC.
In the camera(an AXIS Product) is a relay. In a Browser I can simply switch the relay by input the URL :
http://cameraname/io/relayon.txt

My question:How can I switch the relay from a Java Applet?

I've tried it like this:


private synchronized void reopenURL( URL urlOpen )
{
    try
    {
      URLConnection connect = urlOpen.openConnection();
             
      connect.setDefaultAllowUserInteraction( true );
                        
        connect.setUseCaches( false );

      connect.setDoInput( true );       

      connect.connect();

      InputStream inputstream = connect.getInputStream();

      while( inputstream.read() >= 0 );
             inputstream.close();
        }
      catch( IOException e )
      {
            String m_strIOExcept = e.getMessage();
      }
}

public void setRelayOn()
{
        try
      {
      
       URL url = newURL("http","webcam",80,"/io/input.txt");
       reopenURL(url);
}
      catch (MalformedURLException m)
      {
            String test = m.getMessage();      
      }
            
This is my own written class (not exactly of course)
The method setRelayOn() is called by the Applet.
If I debug the program there is the same mistake every time.
When I reach the line connect.connect() I receive the error message "java/net/URLConnection: field url not found"!

Thanks for your help.
0
Comment
Question by:mkaufman
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
russgold earned 100 total points
ID: 1230588
If you can normally do what you want from a browser using http, just call showDocument() on your applet context:


URL cameraSwitch = new URL( "http://cameraname/io/relayon.txt" );
getAppletContext(). showDocument( cameraSwitch );
0
 

Author Comment

by:mkaufman
ID: 1230589
I,ve tried it and it works!!!!
thank you very,very much!!!!!
0
 

Author Comment

by:mkaufman
ID: 1230590
In your example, how can I prevent, that the Browser use caches?
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

770 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