我目前正在构建一些网络应用程序。
其中一个方法ANDgate()
使用套接字传输一些字节。
客户端
public static ArrayList ANDgate(ArrayList bits, ArrayList macs, ArrayList tags, int gateNumber) throws IOException, GeneralSecurityException, ClassNotFoundException
{
Socket s= new Socket("192.168.1.109", 8888);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(s.getInputStream());
//Some computation
oos.writeByte(p);
oos.flush();
oos.writeByte(p1);
oos.flush();
//Some computation
byte P = ios.readByte();
byte P1 = ios.readByte();
//Some computation
oos.writeByte(p_shared1);
oos.flush();
//Some computation
byte p_shared2 = ios.readByte();
//Some computation
oos.writeByte(p1_shared2);
oos.flush();
//Some computation
oos.close();
ios.close();
s.close();
}
在服务器端,我有几乎相同的代码。 运行程序时,可以成功调用和执行此方法1000次(或更多次),但随机出现以下错误
Exception in thread "main" java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at Gate.ANDgate(Gate.java:119)
119行是ObjectInputStream ios = new ObjectInputStream(s.getInputStream());
提前感谢您的帮助