Few hours ago I have started to learn java socket comunication. Now I’m trying to make server application whitch should return me data to webbrowser.
My code:
try{
ServerSocket socket = new ServerSocket(80);
Socket response = socket.accept();
String lol = "<html>hi</html>";
OutputStream str = response.getOutputStream();
str.write(lol.getBytes("US-ASCII"));
str.flush();
response.close();
System.out.println("LOL works!");
}catch(IOException ex)
{
System.out.println(ex.toString());
}
}
I have no error in server application, the message “LOL works!!!” prints in console but in webbrowser I’m getting this error:

Does anobody know how to repair it and get the text “hi” in webbrowser? Thanks.
EDIT:
I’ve tried add it to telnet. This is the result:

You cannot just send out raw data to the browser and expect it to handle it – you have to follow the HTTP (protocol) which is described in RFC1945.
Specifically, you have to send out a few headers followed by a new line first as described in Section 4.1 of RFC1945.
Note that I’ve also wrapped your OutputStream in a PrintStream, since this is a lot easier than handling the OutputStream manually.