Exception: Connection reset

Hi,

I use this code

import java.io.*;

import java.net.*;

...

publicvoid run(){

try{

ServerSocket ss =new ServerSocket(TCP_PORT);

while (true){

Socket sock = ss.accept();

in =new BufferedReader(

new InputStreamReader(

sock.getInputStream()));

out =new PrintWriter(

new BufferedWriter(

new OutputStreamWriter(

sock.getOutputStream())),true);

String msg = in.readLine();

}

}catch (Exception ex){

serverLog("while exception: " + ex.getMessage());

}

}

...

BufferedReader in;

PrintWriter out;

When this part of code will logwhile exception: Connection reset?

Thank you.

[1493 byte] By [boba5555a] at [2007-11-26 16:03:54]
# 1
Probably never. You mostly get this on writing, not reading.Do you plan on closing the accepted sockets any time?
ejpa at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 2
I am closing accepted sockets. I didn't post you whole code, only part which takes connection.> You mostly get this on writing, not reading.What can be cause? I got that message.
boba5555a at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 3
Post a stack trace and the full error message of the exception you get.
sjasjaa at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 4

Does ex.toString() will write the whole message (the same as printStactTrace)? Then I should change code and wait for another error (I hope it will not happen again). It should work during the whole day at least for two months.

What is "usual" time after which some server (ie. java server) should be rebooted?

boba5555a at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 5

> Does ex.toString() will write the whole message

> (the same as printStactTrace)?

Nope, you should usually do both when you have a catch block. (There are some situations where an exception is expected and does not require operator intervention, so a trace may be skipped.)

If you only have the message, or the stack trace, post those, complete and unedited; maybe someone can figure something out from them. In particular, I'm looking for any hint to what operation caused the error: accept, read, write, select, ...

> What is "usual" time after which some server (ie. java server)

> should be rebooted?

If you have a properly written program, with no memory leaks and such, there should be no reason ever to restart the program or reboot the server. Only things like critical operating system patches or hardware upgrades should require a reboot.

sjasjaa at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 6
I got only Connection reset - I didn't edit it.
boba5555a at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 7
Can you please print the stack trace as requested by sjasja in reply #3.
ejpa at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 8

I want, but I cann't get it again. I use some program which makes java file to be service, so I don't see what write in a console, only what I can log into file, because that I aksed what can be cause, some "global" cause.... If I get it again, I will send here the whole stackTrace, if ex.toString() will log the same as ex.printStackTrace()...

boba5555a at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 9
ejp,please could you help me with my assignment, which I'm sure that you will find easy? I'm desperate now! It's a User Interface...
nightprowlera at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...
# 10
You mean help you cheat by passing off my work as yours?
ejpa at 2007-7-8 22:25:48 > top of Java-index,Archived Forums,Socket Programming...