Best way detect Network and Internet Connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?=

    Best way detect Network and Internet Connection

    Hi all mister,



    Which is THE BEST WAY IN THE WORLD AROUND for:



    1. detect Network



    2. detect Internet Connection is working...



    which is the best way in the world and good practice recommended by MVPs
    Microsoft ?



    Thanks in advanced..



    code below...but which is the best code ???



    NetworkInterfac e.GetIsNetworkA vailable()



    private static int ERROR_SUCCESS = 0;
    public static bool IsInternetConne cted() {
    long dwConnectionFla gs = 0;
    if (!InternetGetCo nnectedState(dw ConnectionFlags , 0))
    return false;

    if(InternetAtte mptConnect(0) != ERROR_SUCCESS)
    return false;

    return true;
    }


    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern int InternetAttempt Connect(uint res);


    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern bool InternetGetConn ectedState(long flags,long
    reserved);


    Correct translation below.


    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern bool InternetGetConn ectedState(out int flags,int
    reserved);



    I found code in C#, how convert to VB.NET



    HttpWebRequest req;
    HttpWebResponse resp;
    try
    {
    req = (HttpWebRequest )WebRequest.Cre ate("http://www.google.com" );
    resp = (HttpWebRespons e)req.GetRespon se();

    if(resp.StatusC ode.ToString(). Equals("OK"))
    {
    Console.WriteLi ne("its connected.");
    }
    else
    {
    Console.WriteLi ne("its not connected.");
    }
    }
    catch(Exception exc)
    {
    Console.WriteLi ne("its not connected.");
    }



    --





  • Teme64

    #2
    Re: Best way detect Network and Internet Connection

    Alhambra Eidos Desarrollo wrote:
    Hi all mister,
    >
    >
    >
    Which is THE BEST WAY IN THE WORLD AROUND for:
    >
    >
    >
    1. detect Network
    >
    >
    >
    2. detect Internet Connection is working...
    >
    >
    >
    which is the best way in the world and good practice recommended by MVPs
    Microsoft ?
    >
    >
    >
    Thanks in advanced..
    >
    >
    >
    code below...but which is the best code ???
    >
    >
    >
    NetworkInterfac e.GetIsNetworkA vailable()
    >
    >
    >
    private static int ERROR_SUCCESS = 0;
    public static bool IsInternetConne cted() {
    long dwConnectionFla gs = 0;
    if (!InternetGetCo nnectedState(dw ConnectionFlags , 0))
    return false;
    >
    if(InternetAtte mptConnect(0) != ERROR_SUCCESS)
    return false;
    >
    return true;
    }
    >
    >
    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern int InternetAttempt Connect(uint res);
    >
    >
    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern bool InternetGetConn ectedState(long flags,long
    reserved);
    >
    >
    Correct translation below.
    >
    >
    [DllImport("wini net.dll", SetLastError=tr ue)]
    public static extern bool InternetGetConn ectedState(out int flags,int
    reserved);
    >
    >
    >
    I found code in C#, how convert to VB.NET
    >
    >
    >
    HttpWebRequest req;
    HttpWebResponse resp;
    try
    {
    req = (HttpWebRequest )WebRequest.Cre ate("http://www.google.com" );
    resp = (HttpWebRespons e)req.GetRespon se();
    >
    if(resp.StatusC ode.ToString(). Equals("OK"))
    {
    Console.WriteLi ne("its connected.");
    }
    else
    {
    Console.WriteLi ne("its not connected.");
    }
    }
    catch(Exception exc)
    {
    Console.WriteLi ne("its not connected.");
    }
    >
    Converted with http://www.developerfusion.com/tools.../csharp-to-vb/

    Dim req As HttpWebRequest
    Dim resp As HttpWebResponse
    Try
    req = DirectCast(WebR equest.Create(" http://www.google.com" ), HttpWebRequest)
    resp = DirectCast(req. GetResponse(), HttpWebResponse )

    If resp.StatusCode .ToString().Equ als("OK") Then
    Console.WriteLi ne("its connected.")
    Else
    Console.WriteLi ne("its not connected.")
    End If
    Catch exc As Exception
    Console.WriteLi ne("its not connected.")
    End Try

    --

    Teme64 @ http://windevblog.blogspot.com

    Comment

    • =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?=

      #3
      Re: Best way detect Network and Internet Connection



      And which is the best way to do this:

      detect Network

      detect Internet Connection

      Thanks !!!

      Comment

      • G.S.

        #4
        Re: Best way detect Network and Internet Connection

        On Oct 30, 3:31 am, Alhambra Eidos Desarrollo
        <AlhambraEidosD esarro...@discu ssions.microsof t.comwrote:
        And which is the best way to do this:
        >
        detect Network
        >
        detect Internet Connection
        >
        Thanks !!!
        Sorry - I cannot answer your direct question, but I will be facing
        your issue in a few weeks. My intention was to dig deep into how
        Microsoft deal with it in the impelementation of their Disconnected
        Service Agent Application block... There's plenty info about it on the
        net.. here's an example:

        Maybe you can integrate that block instead...

        Comment

        Working...