ServerSocket server = new ServerSocket(8080);
System.out.println("服务端启动");
Socket socket=server.accept();
OutputStream out=null;
OutputStreamWriter ow=null;
PrintWriter pw=null;
try {
//接受一个客户端
/**向客户端输出
* 先获取字符输出流
*/
out=socket.getOutputStream();
ow=new OutputStreamWriter(out);
pw=new PrintWriter(ow);
String str="<html> <body> tcp返回浏览器数据</body></html>";
pw.println(str);
pw.flush(); //将数据输出
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}catch(Exception e){
e.printStackTrace();
}
}
qq_岁月静好与君语_0
_潇潇暮雨
相关分类