Hi there
I writing a application which is including a server and a client based on TCP.
server:
socket = serverSokcet.accept();
OutputStream out = new BufferedOutputStream(socket.getInputStream());
InputStream file = new FileInputStream("someFile.jpg"); // the file is more than 100KB
int c = file.read();
while(c > -1){
out.write(c);
c = file.read();
}
out.flush();
socket.close();
file.close();
Client:
OutputStream out = new BufferedOutputStream(socekt.getOutputStream()); // the socket has connected the server
out.write("someLine".getBytes()); // becouse the server never read from the client ,so these bytes would be lost
InputStream in = socket.getInputStream();
OutputStream anotherFile = new FileOutputStream("anotherFile");
int c = in.read();
while(c > -1){
anotherFile.write(c);
c = in.read(); // this line will throw the java.net.SocketException: Connection reset after receive some bytes from the servre!
// if I the client dosen't send any data to the server, the Exception will go away
}
sokcet.close()
anotherFile.close();
Why java.net.SocketException? Isn't TCP/IP of Duplex Separation?