1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to send html page as response to client from server?

Discussion in 'C' started by samya, Feb 12, 2009.

  1. samya

    samya New Member

    Joined:
    Feb 12, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hello everybody,

    This is my first post in this forum. I am a biginner in Web Server and Socket Programming. I have made a server in C which listens its 80 port using socket. When any client application sends some message to server, the server application is able to read it.

    If client type .... ServerIP/mypage.html in its browser, the request comes to server. Now I want to send mypage.html(which is stored in my local folder) to client as response and it will be displayed in Client's browser. How can I do it? Please help me. Thank you for your help in advance.

    Thanks
    Samya
     
  2. samya

    samya New Member

    Joined:
    Feb 12, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    In this topic I was unable to send full HTTP path (.... ServerIP/mypage.html still I can not, so usiing...,,plz unserstand) because it did not allow me to post any link and give me error.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    First you should Listen to Port 80

    When you are done with listening to port 80 try to view your web page.

    It would give you some response in your listener.

    I mean when browser sends a request to the ip at port 80 it uses HTTP Protocol to send lots of data to the server and in return server process that request and return the data.

    Are you able to get the response from the browser on the port you are listening and if yes what you are getting ?
     
  4. samya

    samya New Member

    Joined:
    Feb 12, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Yes.... I am getting the following from client :

    GET /mypage.html HTTP/1.1..Accept: image/gif, image/x-xbitmap,...............and some data.

    Thanks
    Samya
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    OK.

    Now You have to understand the HTTP protocol format and send the data using the HTTP format and that would be displayed in the browser.
     
  6. samya

    samya New Member

    Joined:
    Feb 12, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    How can I know HTTP response format? Is there any example (code-snipped)? What should be the exact string the server should send to browser?

    -Samya
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83

Share This Page