Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem about Exception: java.net.SocketException: Connection reset

843790Nov 12 2008 — edited Nov 16 2008
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2008
Added on Nov 12 2008
23 comments
932 views