Tomcat Socket timeout? configuration issue?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aaron_Loucks
Posted On:   Friday, July 2, 2004 06:38 AM

I have a class that makes a socket connection that apears to be timing out. However, no exception is thrown. If I run the program independantly of tomcat it works flawlessly everytime, but when i access the class from a jsp/servlet I get weird results. ... Socket s = new Socket(HOST, PORT); PrintStream sout = new PrintStream(s.getOutputStream(), true); BufferedReader sin = new BufferedReader(new InputStreamReader(s.getInputStream())); // ose.get() returns the data (char[]) to be sent // over the socket. int len = ose.get().length; // tell the server how much data we are about to send    More>>

I have a class that makes a socket connection that apears to be timing out. However, no exception is thrown. If I run the program independantly of tomcat it works flawlessly everytime, but when i access the class from a jsp/servlet I get weird results.



...

Socket s = new Socket(HOST, PORT);

PrintStream sout = new PrintStream(s.getOutputStream(), true);

BufferedReader sin = new BufferedReader(new InputStreamReader(s.getInputStream()));



// ose.get() returns the data (char[]) to be sent

// over the socket.

int len = ose.get().length;




// tell the server how much data we are about to send

// and then send it.

sout.println(len);

sout.println(ose.get());



// ... server processes data and returns some data. ...

// usually between ~ 0-2 seconds



// read one line of text: the amount of data we will be
// reading.

Integer Int = new Integer(in.readLine());

len = Int.intValue();

char[] buf = new char[len];



// read the data.

sin.read(buf, 0, len);



s.close();

sout.close();

sin.close();

...




Basicly the sin.read(buf, 0, len); isn't reading properly when i access this class in a jsp. (however, len always contains the correct value. buf isn't being filled) If I'm reading a small amount of data ( <30K) I get all of it ~99.9% of the time. But when I reading ~ 40K or more, it seems to cut off randomly without throwing any error.


I packet sniffed and the data is being correctly sent from the server every time. It's as if tomcat is shutting down the socket/and/or the BufferedReader as im trying to read it. Is there any part of the tomcat configuration shuts down sockets after a set amount of time? So far i've only found timeout configuration that refer to http timeouts.


Like i said, it works flawlessly if run standalone. It only has problems when run from a jsp/servlet. This leads me to think its something with tomcat. please help!

   <<Less

Re: Tomcat Socket timeout? configuration issue?

Posted By:   Aaron_Loucks  
Posted On:   Friday, July 2, 2004 07:16 AM

I fixed it, but i'm not really sure why it made a difference. The BufferedReader should handle how sin is read, but whatever. I still don't understand why the old version worked before when run from outside tomcat.

for (int i=0; i
sin.read(buf, i, 1);

}

About | Sitemap | Contact