I didn't pay attention to the flush () method of write when I first learned stream, and today when I was learning Network programming, I noticed
Server-side:
Import Java.net.*;import java.io.*;p ublic class client{public static void Main (string[] args) throws Exception { Socket socket = new socket ("localhost", 8888); Bufferedoutputstream out = new Bufferedoutputstream (Socket.getoutputstream ()); byte[] buff = new Byte[2048];for ( int i = 0; I < 2048; i + +) {Buff[i] = ' a ';} Out.write (buff); Out.flush (); Out.close (); Socket.close (); System.out.println ("Send over!");}}
Client:
Import Java.net.*;import java.io.*;p ublic class client{public static void Main (string[] args) throws Exception { Socket socket = new socket ("localhost", 8888); Bufferedoutputstream out = new Bufferedoutputstream (Socket.getoutputstream ()); byte[] buff = new Byte[2048];for ( int i = 0; I < 2048; i + +) {Buff[i] = ' a ';} Out.write (buff); Out.flush (); Out.close (); Socket.close (); System.out.println ("Send over!");}}
When a client lacks a flush statement and close is not closed
----------Java----------
Wait for connection ...
Exception in thread "main" java.net.SocketException:Connection Reset
At Java.net.SocketInputStream.read (Unknown Source)
At Java.net.SocketInputStream.read (Unknown Source)
At Java.io.BufferedInputStream.fill (Unknown Source)
At Java.io.BufferedInputStream.read1 (Unknown Source)
At Java.io.BufferedInputStream.read (Unknown Source)
At Java.io.FilterInputStream.read (Unknown Source)
At Server.main (server.java:13)
Output complete (5 seconds)-Normal termination
Java.net.SocketException:Connection Reset exception for Java network programming