I have the following code:
try
{
ServerSocket serverSocket = new ServerSocket(9090);
System.out.println("wainting for clients...");
Socket socket = serverSocket.accept();
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("Hello client!");
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String clientInput = input.readLine();
System.out.println(clientInput);
input.close();
out.close();
socket.close();
serverSocket.close();
} catch (Exception e)
{
System.out.println(e);
}
When I try to open it in my browser by typing 127.0.0.1:9090, I get the following Error in the console:
GET / HTTP/1.1
And in the browser I get:
127.0.0.1 refuse to connect
My code and output:
Instructor code:
Instructor output:
I tried many solutions, like using different ports, and allowing the browser on firewall, but none of these solutions worked.
I could not find a solution for Java.
Advertisement
Answer
I got the answer from @dan1st, and the answer is that only Firefox browser allows raw TCP messages


