I’m trying to send ‘index.html’ code with Java socket wrapped in BufferedWriter. When I open browser and connect to ‘localhost:port’ I get:
- text output (
<head>...</head> <body>...</body>) – firefox@linux - text output – chrome@linux
- correct web page view – konqueror@linux
- text output – firefox@windows7
How can I fix this to get correct view for every browser?
Based on your description, it sounds like your code is severely violating the HTTP protocol and each browser is handling this violation differently. The first thing you need to do is brush up on HTTP see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6
Sounds like you are not sending the response status line, required headers including Content-Length etc, followed by the message body (your index.html)
After reading RFC2616 and realizing what is involved in conforming to the HTTP protocol, you may want to reconsider doing this yourself, and look into using any of several frameworks to handle this for you – Tomcat and Jetty being very popular Java based HTTP frameworks. Netty is also an option, being a more lightweight customizable framework.