You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by alex reuter <ar...@monsterdaata.com> on 2001/08/13 22:10:15 UTC
Connection reset by peer: socket write error NOT harmless
Hello List!
This is my first post here, so sorry for the length.
I'm running a binary distribution of tomcat 3.2.3 on Windows NT, developing
in JDDeveloper 3.2.2.
I have a client java program which sends a simple SQL string to a servlet
which gets an image from our database and returns it. No browsers involved.
The problem I'm having is that a third of the time when I execute the client
request from my computer to the local IP address of tomcat, also running on
my computer, tomcat gives this error message:
2001-08-13 15:39:03 - Ctx( /databasefetcher ): IOException in:
( /databasefetcher + /servlet/databasefetcher + null) Connection reset by
peer: socket write error
And the file, which the client program writes to the file system, is
corrupted.
If tomcat does not give this error message, the image is fine and can be
opened and enjoyed for all of its beauty.
The images are tiffs and are about 250K in size each. Below is the code for
the fetching:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
//read in the SQL string
BufferedReader br = new BufferedReader(new
InputStreamReader(req.getInputStream()));
String SQL = "" +br.readLine();
try{
//get the image from the database
ResultSet rs = (ResultSet)Enterpriser.dealWithDbFetch(SQL, false);
InputStream isImg=null;
if(rs.next()){
isImg = rs.getBinaryStream(1);
}
//set the length to 1.3 mb, the largest image size
res.setContentLength(1300000);
res.setContentType("image/tif");
res.setBufferSize(1300000);
byte[] b = new byte[1300000];
//read the image into the inputstream
isImg.read( b );
//get the servlet output stream
ServletOutputStream out = res.getOutputStream();
//write the image to the response
out.write(b);
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
++++++++++++++++++++++++++++++++++++
AND here is the code for the client program:
++++++++++++++++++++++++++++++++++++++
import java.net.*;
import java.io.*;
import org.xml.sax.*;
import java.util.Properties;
public class StringHttp {
// POST an XML document to a Service's URL, Returning XML document
response
public static InputStream doPost(String stringToPost, URL target)
throws IOException, ProtocolException {
// (1) Open an HTTP connection to the target URL
HttpURLConnection conn = (HttpURLConnection)target.openConnection();
if (conn == null) return null;
// (2) Use HTTP POST
conn.setRequestMethod("POST");
// (3) Indicate that the content type is plain text with appropriate
MIME type
conn.setRequestProperty("Content-type","text/plain");
// (4) We'll be writing and reading from the connection
conn.setDoOutput(true);
conn.setDoInput(true);
// (5) Print the String into the connection's output stream
PrintWriter pw = new PrintWriter( new
utputStreamWriter( conn.getOutputStream()));
pw.println( stringToPost ); // etc, etc.
pw.flush();
pw.close();
// (6) Get an InputStream to read the response from the server.
InputStream responseStream = conn.getInputStream();
return responseStream;
}
public static void main(String args[]){
String SQL="Select A.MAP from a TABLE where map_id=1";
try{
URL dispatchURL = new
URL("http://192.1.1.215:8080/databasefetcher/servlet/databasefetcher");
long start = System.currentTimeMillis();
InputStream is = StringHttp.doPost(SQL, dispatchURL);
long end = System.currentTimeMillis()-start;
System.out.println("Took "+ end+ " millis");
byte[] b = new byte[1300000];
is.read(b);
FileOutputStream fos = new FileOutputStream(new
File("C:\\imgTest3.tif"));
fos.write(b);
}
catch(Exception e){
e.printStackTrace();
}
}
}
+++++++++++++++++++++++++++++++++++++++++
I've seen a number of posts on this subject and the answer always seems to
have to do with IE. I'm not using it. Though sometimes IIS starts up
acidentally, cutting apache out of the loop.
Any help is greatly appreciated.
Thanks,
Alex
RE: Connection reset by peer: socket write error NOT harmless
Posted by alex reuter <ar...@monsterdaata.com>.
Just to give you some more background info(you being the kind hearted soul
who read my last post) The image is ALWAYS corrupted if I run the client
program from another machine on our local network.
Also, if I add the following line of code to the servlet:
out.flush();
sandwiched between:
out.write(b);
out.close();
I get a much more robust error, namely:
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
Thanks again .
Alex
-----Original Message-----
From: alex reuter [mailto:areuter@monsterdaata.com]
Sent: Monday, August 13, 2001 4:10 PM
To: tomcat-user@jakarta.apache.org
Subject: Connection reset by peer: socket write error NOT harmless
Hello List!
This is my first post here, so sorry for the length.
I'm running a binary distribution of tomcat 3.2.3 on Windows NT, developing
in JDDeveloper 3.2.2.
I have a client java program which sends a simple SQL string to a servlet
which gets an image from our database and returns it. No browsers involved.
The problem I'm having is that a third of the time when I execute the client
request from my computer to the local IP address of tomcat, also running on
my computer, tomcat gives this error message:
2001-08-13 15:39:03 - Ctx( /databasefetcher ): IOException in:
( /databasefetcher + /servlet/databasefetcher + null) Connection reset by
peer: socket write error
And the file, which the client program writes to the file system, is
corrupted.
If tomcat does not give this error message, the image is fine and can be
opened and enjoyed for all of its beauty.
The images are tiffs and are about 250K in size each. Below is the code for
the fetching:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
//read in the SQL string
BufferedReader br = new BufferedReader(new
InputStreamReader(req.getInputStream()));
String SQL = "" +br.readLine();
try{
//get the image from the database
ResultSet rs = (ResultSet)Enterpriser.dealWithDbFetch(SQL, false);
InputStream isImg=null;
if(rs.next()){
isImg = rs.getBinaryStream(1);
}
//set the length to 1.3 mb, the largest image size
res.setContentLength(1300000);
res.setContentType("image/tif");
res.setBufferSize(1300000);
byte[] b = new byte[1300000];
//read the image into the inputstream
isImg.read( b );
//get the servlet output stream
ServletOutputStream out = res.getOutputStream();
//write the image to the response
out.write(b);
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
++++++++++++++++++++++++++++++++++++
AND here is the code for the client program:
++++++++++++++++++++++++++++++++++++++
import java.net.*;
import java.io.*;
import org.xml.sax.*;
import java.util.Properties;
public class StringHttp {
// POST an XML document to a Service's URL, Returning XML document
response
public static InputStream doPost(String stringToPost, URL target)
throws IOException, ProtocolException {
// (1) Open an HTTP connection to the target URL
HttpURLConnection conn = (HttpURLConnection)target.openConnection();
if (conn == null) return null;
// (2) Use HTTP POST
conn.setRequestMethod("POST");
// (3) Indicate that the content type is plain text with appropriate
MIME type
conn.setRequestProperty("Content-type","text/plain");
// (4) We'll be writing and reading from the connection
conn.setDoOutput(true);
conn.setDoInput(true);
// (5) Print the String into the connection's output stream
PrintWriter pw = new PrintWriter( new
utputStreamWriter( conn.getOutputStream()));
pw.println( stringToPost ); // etc, etc.
pw.flush();
pw.close();
// (6) Get an InputStream to read the response from the server.
InputStream responseStream = conn.getInputStream();
return responseStream;
}
public static void main(String args[]){
String SQL="Select A.MAP from a TABLE where map_id=1";
try{
URL dispatchURL = new
URL("http://192.1.1.215:8080/databasefetcher/servlet/databasefetcher");
long start = System.currentTimeMillis();
InputStream is = StringHttp.doPost(SQL, dispatchURL);
long end = System.currentTimeMillis()-start;
System.out.println("Took "+ end+ " millis");
byte[] b = new byte[1300000];
is.read(b);
FileOutputStream fos = new FileOutputStream(new
File("C:\\imgTest3.tif"));
fos.write(b);
}
catch(Exception e){
e.printStackTrace();
}
}
}
+++++++++++++++++++++++++++++++++++++++++
I've seen a number of posts on this subject and the answer always seems to
have to do with IE. I'm not using it. Though sometimes IIS starts up
acidentally, cutting apache out of the loop.
Any help is greatly appreciated.
Thanks,
Alex