Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to send html page as response to client from server? (http://www.go4expert.com/forums/send-html-page-response-client-server-t16165/)

samya 12Feb2009 23:30

How to send html page as response to client from server?
 
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

samya 12Feb2009 23:34

Re: How to send html page as response to client from server?
 
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.

shabbir 13Feb2009 09:02

Re: How to send html page as response to client from server?
 
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 ?

samya 13Feb2009 13:08

Re: How to send html page as response to client from server?
 
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

shabbir 13Feb2009 14:35

Re: How to send html page as response to client from server?
 
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.

samya 13Feb2009 14:50

Re: How to send html page as response to client from server?
 
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

shabbir 13Feb2009 15:10

Re: How to send html page as response to client from server?
 
Check out http://www.w3.org/Protocols/HTTP/1.0...http-spec.html


All times are GMT +5.5. The time now is 15:14.