我得到以下EOFException
同时使用readUTF()
方法,请让我知道我是怎么克服这个问题,也请建议如何在其他网络EOFException类中的readUTF
import java.io.*;
import java.net.*;
public class GreetingServer {
public static void main(String args[]) {
String servername =args[0];
int port = Integer.parseInt(args[1]);
try {
System.out.println("Server Name "+ servername +"Port"+port);
Socket client = new Socket(servername,port);
System.out.println("Just connected to"+ client.getRemoteSocketAddress());
OutputStream outs = client.getOutputStream();
DataOutputStream dout = new DataOutputStream(outs);
dout.writeUTF("Hello From"+client.getRemoteSocketAddress());
InputStream in = client.getInputStream();
DataInputStream din = new DataInputStream(in);
System.out.println("Server Says"+ din.readUTF());
client.close();
}
catch (EOFException f) {
f.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
显示你的服务器端代码。问题应该在服务器端发送不正确/不完整的数据 – Tala