网络错误:Broken pipe 是怎么回事? - [Ljava.lang.StackTraceElement;@58e2a12009-05-12 09:49:30,646 [Thread-17]- 网络错误:Socket closed网络错误:Broken pipe 怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 网络断开了,或者使用ObjectStream的时候,对象协议出现不一致。查通信双方的匹配。 private Socket skt; private OutputStream out = null; private ObjectOutputStream oos=null;public boolean send(Object data) { boolean ret = false; try { if (out != null && oos != null) { oos.writeObject(data); oos.flush(); sendCounts++; ret = true; } } catch (IOException ex) { Log.getInstance().outLog("发送对象网络错误 IOException ex:"+ex.getMessage()); ex.printStackTrace(); try {// if (in != null) {// in.close();// } if (out != null) { out.close(); out = null; } if ( oos != null ){ oos.close(); oos = null; } if (skt != null) { skt.close(); } } catch (IOException ex2) { } catch (Exception ex2) { } isError = true; } catch (Exception ex) { Log.getInstance().outLog("发送对象网络错误Exception ex:"+ex.getMessage());// ex.printStackTrace(); try {// if (in != null) {// in.close();// } if (out != null) { out.close(); } if (skt != null) { skt.close(); } } catch (IOException ex2) { Log.getInstance().outLog("发送对象网络错误IOException ex2:"+ex2.getMessage()); } catch (Exception ex2) { Log.getInstance().outLog("发送对象网络错误:"+ex2.getMessage()); } out = null; skt = null; isError = true; } return ret; } 看着代码处理的有什么问题?if (!RecvCenter.getInstance().send(data)) { tcl.add(data); Log.getInstance().outLog("发送对象数据到数据服务中心失败"); //为什么会发送失败?失败后如何处理??? Thread.sleep(500); } else { Log.getInstance().outLog("发送对象数据到数据服务中心成功"); } //发送后是否要将线程关闭或挂起?????RecvCenter.java:import java.io.IOException;import java.io.InputStream;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.OutputStream;import java.net.Socket;import java.net.UnknownHostException;import sany.config.Config;import sany.log.Log;public class RecvCenter extends Thread { private String dbserver; private int port; private Socket skt; private OutputStream out = null; private ObjectOutputStream oos=null; private boolean isError = true; private static RecvCenter instance = null; private long sendCounts=1;//测试发送的对象数目 public static synchronized RecvCenter getInstance() { if (instance == null) { instance = new RecvCenter(); instance.start(); } return instance; } public RecvCenter() { dbserver = Config.getProperty("dbserver"); port = Config.getInt("dbport")+2; } public void run() { while (true) { //与服务器建立连接开始 if (skt == null) { try { skt = new Socket(dbserver, port); if ( null == skt ){ Thread.sleep(500); continue; } out = skt.getOutputStream(); oos = new ObjectOutputStream(out);//0x aced 05 Log.getInstance().outLog("链接到接收中心" + dbserver + ";" + port); isError = false; } catch (UnknownHostException ex) { try { if ( skt != null ) skt.close(); } catch (IOException e) { e.printStackTrace(); } skt = null; } catch (IOException ex) { try { Log.getInstance().outLog("链接到接收中心出错,"+ex.getMessage()); if ( skt != null ) skt.close(); } catch (IOException e) { e.printStackTrace(); } skt = null; } catch (Exception ex) { try { if ( skt != null ) skt.close(); } catch (IOException e) { e.printStackTrace(); } skt = null; } } //与服务器建立连接完毕 if (isError) { try { if (out != null) { out.close(); } if (skt != null) { skt.close(); } } catch (IOException ex2) { } catch (Exception ex) { } out = null; skt = null; } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } public boolean send(Object data) { boolean ret = false; try { if (out != null && oos != null) { oos.writeObject(data); oos.flush(); sendCounts++; ret = true; } } catch (IOException ex) { Log.getInstance().outLog("发送对象网络错误 IOException ex:"+ex.getMessage()); ex.printStackTrace(); try { if (out != null) { out.close(); out = null; } if ( oos != null ){ oos.close(); oos = null; } //SOCKET关闭后,怎么办?重新建立连接? if (skt != null) { skt.close(); } } catch (IOException ex2) { } catch (Exception ex2) { } isError = true; } catch (Exception ex) { Log.getInstance().outLog("发送对象网络错误Exception ex:"+ex.getMessage()); try { if (out != null) { out.close(); } if (skt != null) { skt.close(); } } catch (IOException ex2) { Log.getInstance().outLog("发送对象网络错误IOException ex2:"+ex2.getMessage()); } catch (Exception ex2) { Log.getInstance().outLog("发送对象网络错误:"+ex2.getMessage()); } out = null; skt = null; isError = true; } return ret; }} jboss发布实体bean报错 webservice问题,java调用webservice方法报错 各位,启动tomcat的时候报了这个错误,牛人帮我看一下哦。谢谢了 用cxf或者AXIS2生成的JAVA客户端,必须要导入相关的包才能使用嘛? Swing如何实现JComboBox中下拉带JCheckBox复选 急救!! spring + struts + hibernate cmp一问 这里好冷清啊, 哪里的EJB高手比较多? 关于JBuilder中jtree的问题,高手请进 java连接oracle字符串问题 div层如何显示相对路径上的图片 java调用c++的exe文件和方法!
private Socket skt;
private OutputStream out = null;
private ObjectOutputStream oos=null;public boolean send(Object data) {
boolean ret = false;
try {
if (out != null && oos != null) {
oos.writeObject(data);
oos.flush();
sendCounts++;
ret = true;
}
} catch (IOException ex) {
Log.getInstance().outLog("发送对象网络错误 IOException ex:"+ex.getMessage());
ex.printStackTrace();
try {
// if (in != null) {
// in.close();
// }
if (out != null) {
out.close();
out = null;
}
if ( oos != null ){
oos.close();
oos = null;
}
if (skt != null) {
skt.close();
}
} catch (IOException ex2) {
} catch (Exception ex2) { }
isError = true;
} catch (Exception ex) {
Log.getInstance().outLog("发送对象网络错误Exception ex:"+ex.getMessage());
// ex.printStackTrace();
try {
// if (in != null) {
// in.close();
// }
if (out != null) {
out.close();
}
if (skt != null) {
skt.close();
}
} catch (IOException ex2) {
Log.getInstance().outLog("发送对象网络错误IOException ex2:"+ex2.getMessage());
} catch (Exception ex2) {
Log.getInstance().outLog("发送对象网络错误:"+ex2.getMessage());
}
out = null;
skt = null;
isError = true;
}
return ret;
}
if (!RecvCenter.getInstance().send(data)) {
tcl.add(data);
Log.getInstance().outLog("发送对象数据到数据服务中心失败");
//为什么会发送失败?失败后如何处理???
Thread.sleep(500);
} else {
Log.getInstance().outLog("发送对象数据到数据服务中心成功");
}
//发送后是否要将线程关闭或挂起?????RecvCenter.java:import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;import sany.config.Config;
import sany.log.Log;public class RecvCenter extends Thread {
private String dbserver;
private int port;
private Socket skt;
private OutputStream out = null;
private ObjectOutputStream oos=null; private boolean isError = true;
private static RecvCenter instance = null;
private long sendCounts=1;//测试发送的对象数目 public static synchronized RecvCenter getInstance() {
if (instance == null) {
instance = new RecvCenter();
instance.start();
}
return instance;
} public RecvCenter() {
dbserver = Config.getProperty("dbserver");
port = Config.getInt("dbport")+2;
} public void run() { while (true) { //与服务器建立连接开始
if (skt == null) {
try {
skt = new Socket(dbserver, port);
if ( null == skt ){
Thread.sleep(500);
continue;
}
out = skt.getOutputStream();
oos = new ObjectOutputStream(out);//0x aced 05
Log.getInstance().outLog("链接到接收中心" + dbserver + ";" + port);
isError = false;
} catch (UnknownHostException ex) {
try {
if ( skt != null ) skt.close();
} catch (IOException e) {
e.printStackTrace();
}
skt = null;
} catch (IOException ex) {
try {
Log.getInstance().outLog("链接到接收中心出错,"+ex.getMessage());
if ( skt != null ) skt.close();
} catch (IOException e) {
e.printStackTrace();
}
skt = null;
} catch (Exception ex) {
try {
if ( skt != null ) skt.close();
} catch (IOException e) {
e.printStackTrace();
}
skt = null;
}
}
//与服务器建立连接完毕
if (isError) {
try {
if (out != null) {
out.close();
}
if (skt != null) {
skt.close();
}
} catch (IOException ex2) {
} catch (Exception ex) {
}
out = null;
skt = null;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public boolean send(Object data) {
boolean ret = false;
try {
if (out != null && oos != null) {
oos.writeObject(data);
oos.flush();
sendCounts++;
ret = true;
}
} catch (IOException ex) {
Log.getInstance().outLog("发送对象网络错误 IOException ex:"+ex.getMessage());
ex.printStackTrace();
try {
if (out != null) {
out.close();
out = null;
}
if ( oos != null ){
oos.close();
oos = null;
}
//SOCKET关闭后,怎么办?重新建立连接?
if (skt != null) {
skt.close();
}
} catch (IOException ex2) {
} catch (Exception ex2) { }
isError = true;
} catch (Exception ex) {
Log.getInstance().outLog("发送对象网络错误Exception ex:"+ex.getMessage());
try {
if (out != null) {
out.close();
}
if (skt != null) {
skt.close();
}
} catch (IOException ex2) {
Log.getInstance().outLog("发送对象网络错误IOException ex2:"+ex2.getMessage());
} catch (Exception ex2) {
Log.getInstance().outLog("发送对象网络错误:"+ex2.getMessage());
}
out = null;
skt = null;
isError = true;
}
return ret;
}}