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

求高手点拨一个Socket通信项目中的错误..
求高手点拨:
    我在进行一个IM工具的书写时,碰到了下面的错误:
    
    我点击其中倒数第二个异常连接,MyEclipse显示出下面的代码界面:
    
    我写出数据的端点的代码如下:
     
    上图中的“readsocketUTF()”方法和“write()”方法源代码如下:
    (写出类和接收类都共用上面的方法)
    
package d_port_package;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class Lib {
    static InputStream inputstream = null;
    static OutputStream outputstream = null;
    static String MyKey = "CJCO5882";
    static PrintStream ps;
    static BufferedReader br;
static String buffer0;
static OutputStream os = null;
    
static String readsocketUTF(Socket s){
        String info = "";
        // 启用输入流
InputStream is = null;
try {
is = s.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputStreamReader isr = new InputStreamReader(is);
br = new BufferedReader(isr);
try {
buffer0 = br.readLine() + "\r\n";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
info = Systemcrypt.HloveyRC4(buffer0.trim(),MyKey);
        return info;
    }

static void write(Socket s,String str0){
try {
os = s.getOutputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ps = new PrintStream(os);
String str = Systemcrypt.HloveyRC4(str0,MyKey);
try {
os = s.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps.println(str);
}
}

    上面的“Systemcrypt类”的源代码如下:
    
package d_port_package;
public class Systemcrypt{

public static String HloveyRC4(String aInput,String aKey)   
    {   
        int[] iS = new int[256];   
        byte[] iK = new byte[256];   
          
        for (int i=0;i<256;i++)   
            iS[i]=i;   
              
        int j = 1;   
          
        for (short i= 0;i<256;i++)   
        {   
            iK[i]=(byte)aKey.charAt((i % aKey.length()));   
        }   
          
        j=0;   
          
        for (int i=0;i<255;i++)   
        {   
            j=(j+iS[i]+iK[i]) % 256;   
            int temp = iS[i];   
            iS[i]=iS[j];   
            iS[j]=temp;   
        }   
      
      
        int i=0;   
        j=0;   
        char[] iInputChar = aInput.toCharArray();   
        char[] iOutputChar = new char[iInputChar.length];