Find the answer to your Linux question:
Results 1 to 5 of 5
Hi I want to create an application to check if a site is active or inactive (homework for networking ). For that I need to connect to the ip at ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3

    Exclamation HTTP status in C

    Hi

    I want to create an application to check if a site is active or inactive (homework for networking ). For that I need to connect to the ip at which the site resides and get the status. For that I create a socket with the IP and the port 80 and try to read an answer.
    First of all I want to ask if this is the correct course of actions.
    Second, I cannot connect with my socket to the designated IP and port 80 - it gives me: Connection refused. How can I connect to the server on which the site resides correctly.
    What message I should send to the server to get as response the status of the site or better an error code (404, 500, 200) from which I can see the status of the site.
    PS. I can use only the standard libraries on C under LINUX (it is a homework and I cannot use libraries made by someone else)

    Thank you in advance. Any help will be much appreciated.

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by anti4kd View Post
    For that I create a socket with the IP and the port 80 and try to read an answer. First of all I want to ask if this is the correct course of actions.
    If you mean by "site" a running http server, yes.
    But keep in mind there is a difference between source and destination port.

    Quote Originally Posted by anti4kd View Post
    Second, I cannot connect with my socket to the designated IP and port 80 - it gives me: Connection refused. How can I connect to the server on which the site resides correctly. What message I should send to the server to get as response the status of the site or better an error code (404, 500, 200) from which I can see the status of the site.
    Every HTTP request returns some status code in the header of the http message if the http server is running and can be reached.

    Read RFC 2616 to learn more about this.


    Quote Originally Posted by anti4kd View Post
    PS. I can use only the standard libraries on C under LINUX (it is a homework and I cannot use libraries made by someone else)
    When I want to get some idea of the traffic, I open netcat or telnet and connect to the server. This way, I can play around and it prints out any answer on my screen. If this works correctly, I implement it in C.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3
    Thank you GNU-Fan for pointing the helpful info.

    I need some samples of C code because I'm more of a PHP programmer and I don't know all the functions needed to do this others from the few I learned at the university.

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by anti4kd View Post
    I need some samples of C code because I'm more of a PHP programmer and I don't know all the functions needed to do this others from the few I learned at the university.
    Oh, there is lots of it.
    For example, HappyHTTP - a simple HTTP library
    Debian GNU/Linux -- You know you want it.

  5. #5
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3
    Thank you again GNU-Fan. This library is the perfect example for me.
    Really appreciate.

Posting Permissions

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