- [Ljava.lang.StackTraceElement;@58e2a1
2009-05-12 09:49:30,646 [Thread-17]- 网络错误:Socket closed网络错误:Broken pipe 怎么解决?

解决方案 »

  1.   

    网络断开了,或者使用ObjectStream的时候,对象协议出现不一致。查通信双方的匹配。
      

  2.   


    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;
    }
      

  3.   

    看着代码处理的有什么问题?
    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;
    }}