public class SerProg {
static ServerSocket ser=null;
static Socket cli=null;
static ObjectInputStream ins=null;
static ObjectOutputStream outs=null;
public static void main(String[] args) {
try {
ser=new ServerSocket(9000,10);
cli=ser.accept();
System.out.println("Connected to :"+cli.getInetAddress().getHostAddress()+" At Port :"+cli.getLocalPort());
ins=new ObjectInputStream(cli.getInputStream());
outs=new ObjectOutputStream(cli.getOutputStream());
String str=(String)ins.readObject();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
和客户端
public class SerProg {
/**
* @param args
*/
static ServerSocket ser=null;
static Socket cli=null;
static ObjectInputStream ins=null;
static ObjectOutputStream outs=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
ser=new ServerSocket(9000,10);
cli=ser.accept();
System.out.println("Connected to :"+cli.getInetAddress().getHostAddress()+" At Port :"+cli.getLocalPort());
ins=new ObjectInputStream(cli.getInputStream());
outs=new ObjectOutputStream(cli.getOutputStream());
String str=(String)ins.readObject();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
连接已成功建立,但在服务器代码行中
ins=new ObjectInputStream(cli.getInputStream());
代码停止并且不继续,可能是什么问题?