日期:2014-05-20  浏览次数:20761 次

求教一个Socket通信的异常修改.
我在写一个Socket通信的程序,今天碰到了一个错误:
    
    点击图中的最后一个连接,得到下面的代码现场:
    
    点击图1中的倒数第二个链接,得到下面的第60行代码现场:
    
package s_port_package_BeiJing;
 
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
 
public class SocketClient {
 
    public Socket getS() {
        return s;
    }
 
    public void setS(Socket s) {
        this.s = s;
    }
 
    private Socket s;
    private InputStream in;
    private OutputStream out;
    private BufferedInputStream inByte;
    private OutputStream outByte;
    private BufferedReader inStr;
    private PrintWriter outStr;
     
    private long size = 0;
 
    public SocketClient(String ip, int port) {
        try {
            s = new Socket(ip, port);
 
            in = s.getInputStream();
            out = s.getOutputStream();
 
            inByte = new BufferedInputStream(in);
            outByte = out;
 
            inStr = new BufferedReader(new InputStreamReader(in));
            outStr = new PrintWriter(new OutputStreamWriter(out));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public String readStr() throws IOException {
        synchronized (this.in) {
            return this.inStr.readLine();
        }
    }
 
    public void writeStr(String content,String MyThreadname) {
        synchronized (this.out) {
            outStr.println(content+"#"+MyThreadname);
            outStr.flush();
        }
    }
 
    public File readToFile(File file) throws IOException {
        synchronized (this.in) {
            FileOutputStream fos = new FileOutputStream(file);
            byte[] temp = new byte[1024 * 8];
            int count = 0;
            while (-1 != (count = this.inByte.read(temp))) {
                fos.write(temp, 0, count);
                fos.flush();
            }
            fos.close();
            return file;
        }
    }
 
    public void writeFile(File file) {
        synchronized (this.out) {
            size = file.length();
            this.noticeFileSize(size);
 
            FileInputStream fis;