欢迎来到天天文库
浏览记录
ID:42575157
大小:23.52 KB
页数:8页
时间:2019-09-18
《Connection reset by peer socket write error错误分析》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、常出现的Connectionresetbypeer:原因可能是多方面的,不过更常见的原因是: ①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉; ②:客户关掉了浏览器,而服务器还在给客户端发送数据; ③:浏览器端按了Stop 通常原因为:远程主机上对等方应用程序突然停止运行,或远程主机重新启动,或远程主机在远程方套接字上使用了“强制”关闭(参见setsockopt(SO_LINGER))。另外,在一个或多个操作正在进行时,如果连接因“keep-alive”活动检测到一个失败而中断,也可能导致此错误。此时,正在进行的操作以错误码WSAENETRESET失败返回,后续操作
2、将失败返回错误码WSAECONNRESET。但是如果频繁出现,就表示很多客户端连接到Apache服务器的响应时间太长了,可能是网络的问题或者服务器性能问题。网友分析:楼主 要从一个被屏蔽的网站上下载一些东西,于是写了一个Servlet,将它传到了一台境外的服务器上. 让这台服务器去下载指定的资源,然后再回传给我.相当于一个代理吧. JAVA codepublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringurl=request
3、.getParameter("url");//得到要下载的资源的URL.if(!StringUtils.isNullOrEmpty(url)){System.out.println(url);URLu=newURL(url);URLConnectionconn=u.openConnection();try{///把响应头设置成一样的.for(Map.Entry>m:conn.getHeaderFields().entrySet()){if(m!=null&&m.getKey()!=null&&m.getValue()!=null&&m.getValu
4、e().size()>0){response.setHeader(m.getKey(),m.getValue().get(0));}}}catch(Exceptione){//TODO:handleexceptione.printStackTrace();CommonLog.log.warn(e);}InputStreamin=conn.getInputStream();//从connection得到inputstreamOutputStreamout=response.getOutputStream();//得到向客户端的输出流try{IOUtils.wrITe(conn.getInpu
5、tStream(),response.getOutputStream());//写数据.}catch(Exceptione){e.printStackTrace();//TODO:handleexceptionCommonLog.log.warn(e);if(in!=null){in.close();}if(out!=null){out.close();}}}}IOUtils.wrITe()代码如下: JAVA code/***从input里面读取数据然后写入output,读完后自动关闭流。*@paraminputinputStream*@paramoutputoutputStream**
6、/publicstaticvoidwrite(InputStreaminput,OutputStreamoutput)throwsIOException{write(input,output,true);}/***自动从inputstream里面读数据,然后写到outputstream里面去。*@paraminputinputstream*@paramoutputoutputstream*@paramclose读完后是否自动关闭流。**/publicstaticvoidwrite(InputStreaminput,OutputStreamoutput,booleanclose)throws
7、IOException{byte[]b=newbyte[1024];intlen=input.read(b);while(len!=-1){output.wrITe(b,0,len);len=input.read(b);}output.flush();if(close){input.close();output.close();}}将程序传到服务器上以后,在服务器上访问 http://localhost:8080/tes
此文档下载收益归作者所有