日期:2014-05-18 浏览次数:20706 次
public static void main(String[] args) {
Socket socket = null;
try {
socket = new Socket("127.0.0.1",4700);
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
dos.writeUTF("客户端,请求建立连接!---消息来自客户端");
System.out.println(dis.readUTF());//这句话为什么跑出下面的异常?应该怎么处理
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(!socket.isClosed()) socket.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at com.test.socket.Client.main(Client.java:15)