字节流,字符流通过网络输入输出--简单例子
@Controller
public class IOController {
@GetMapping("/getString")
public void getString(HttpServletRequest request, HttpServletResponse response) throws IOException {
//获取输入流中的数据
ServletInputStream in = request.getInputStream();
int len = 0;
byte[] b = new byte[1024];
in.read(b);
String str = new String(b,0,b.length);
//通过输出流输出数据
PrintWriter writer = response.getWriter();
writer.println("Hello from controller");
}
}
使用socket通信参考:
https://blog.csdn.net/sundancer_lilong/article/details/50716536