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

samya's Avatar, Join Date: Feb 2009
Newbie Member
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
0
samya's Avatar, Join Date: Feb 2009
Newbie Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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 ?
0
samya's Avatar, Join Date: Feb 2009
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
samya's Avatar, Join Date: Feb 2009
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Check out http://www.w3.org/Protocols/HTTP/1.0...http-spec.html