【发布时间】:2012-02-12 15:46:10
【问题描述】:
几个小时前,我开始学习 java 套接字通信。现在我正在尝试让服务器应用程序将数据返回给 webbrowser。 我的代码:
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());
}
}
我在服务器应用程序中没有错误,消息“LOL 有效!!!”在控制台中打印,但在 webbrowser 中出现此错误:
有人知道如何修复它并在 webbrowser 中获取文本“hi”吗?谢谢。
编辑: 我试过将它添加到telnet。这是结果:
【问题讨论】:
-
您正在侦听端口 80,但通过 HTTPS 连接,默认为端口 443。这是一个问题,确定吗?
-
我正在处理 80。这是我在 google 上找到的第一张图片。