Results 1 to 4 of 4

Thread: WEBClient (Unable To Connect To Remote Server)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    WEBClient (Unable To Connect To Remote Server)

    Ok so..
    I need to read a command from a .html file. To do this I use:
    Code:
      Dim instance As WebClient = New WebClient
       Dim address As String = "www.siteurl.com/file.html"
                        Dim returnValue As String
    
    
                    returnValue = instance.DownloadString(address)
    
    
    
    
                    If returnValue = "open" Then
                      BLAHBLAHBLAH
    I need this to run flawlessly, regardless if the my internet is on or not. If the internet disconnects, I get this (While Debugging):


    returnValue = instance.DownloadString(address)
    Unable to connect to the remote server


    Question:
    My application constantly loops to check the .html file for commands.
    I need it to do this, even if the internet is off. Obviously, it wont read commands if its off.. I just need it to resume reading when it comes back on WITHOUT crashing my application.


    Any code to ignore timeouts so where my application will still TRY to read and not crash.

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: WEBClient (Unable To Connect To Remote Server)

    Code:
    Try
        returnValue = instance.DownloadString(address)
    Catch ex as Exception
        Debug.WriteLine("Timeout... Ignoring...zzz")   
    End Try
    More here:
    http://support.microsoft.com/kb/315965

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WEBClient (Unable To Connect To Remote Server)

    Thank you. It worked, although I did get this:



    Variable 'returnValue' is used before it has been assigned a value. A null reference exception could result at runtime


    Doesnt seem to be causing any trouble though.

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: WEBClient (Unable To Connect To Remote Server)

    it's a warning, not an error. You have no guarantees that 'returnValue' would hold a valid reference. In your case it's nothing to worry about since it's a string. The compiler just points it out to you. If it worries you you can declare it with initialization:

    Code:
    Dim returnValue As String = ""
    The warning will go away.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width