Thread: how can I see if i'm online ?

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    161

    Talking how can I see if i'm online ?

    Hi, there is in C something I can do if I want to see if I'm online ?

    Thanx
    This forum is the best one I've ever seen. Great ppl, great coders

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Find out how to do network connections in C (I think you'd have to have an extra library for this - unless there's a way to route stdin/out through a modem), and then treat it like finding out if opening a file worked. Open a file and then use an if statement on the result of that file. If it returns true - you're connected. If it returns false, you're not.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    "Usually the best way to determine if you have a connection to a particular computer is to attempt the connection."

    Q242558: How To Detecting(sic) If You Have a Connection to the Internet

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    a quick help :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <wininet.h>
    
    int main()
    {
      
    if (InternetGetConnectedState(INTERNET_CONNECTION_OFFLINE,0) == FALSE)
         prinft("1");
         
      else
         printf("2");
      
      system("PAUSE");	
      return 0;
    }
    I link Wininet.lib too....... and I get this :

    8 main.c `INTERNET_CONNECTION_OFFLINE' undeclared (first use in this function)


    why ??


    ps( in the code (INTERNET_CONNECTION_OFFLINE,0) it is bad written but it the forum, not my code)
    This forum is the best one I've ever seen. Great ppl, great coders

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The first argument to the function takes the address of a DWORD that will return additional information.
    Code:
    int main(void)
    {
        DWORD dwState;
    
        if (InternetGetConnectedState(&dwState, 0) == FALSE)
        {
            printf("1");
        }
        else
        {
            printf("2");
        }
    
        system("PAUSE");	
        return 0;
    }
    You may need to update your header/library files.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    ahhhhhhhh now i got it !!!

    thanx
    This forum is the best one I've ever seen. Great ppl, great coders

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in distributing .exe online
    By GamesSmash in forum C++ Programming
    Replies: 31
    Last Post: 11-27-2007, 04:41 PM
  2. 2D Spaceship shooter online - Need 2 keen programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 05-19-2005, 07:40 AM