毕老师的视频学到第24天网络编程中,用浏览器访问自己编写的ServerDemo服务端,但是用浏览器怎么也看不到服务端的内容。服务端返回的浏览器的内容也全是乱码,求解答
服务端代码如下:
import java.net.*;
import java.io.*;
class ServerDemo
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(11000);
Socket s = ss.accept();
System.out.println(s.getInetAddress().getHostAddress());
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
out.println("<font color='red' size='7'>客户端你好</font>");
s.close();
ss.close();
}
}
控制台上显示的浏览器返回的内容如下:
|
|