服务器程序已经启动并且监听了4321这个端口,然后是通过创建NwClient对象 并且调用它的connect函数来进行连接;
编译是没问题的,运行的时候也没有异常抛出的提示但是就在执行 socket = new Socket( host,port)这个语句时停了一小会,下面的输出语句也没有执行,程序自动终止了
main函数中有这个语句:
Singly s2 = new RemoteSingly("Host", 4321);
调用NwClient对象的connect函数的是RemoteSingly构造函数
这个是RemoteSingly的构造函数, ( 成员变量 private NwClient nc = null;)public RemoteSingly( String host, int port )throws Exception{ System.out.println(" new RemoteSingly:");
this.nc = new NwClient( host, port); System.out.println(" Client is connecting Server ");
nc.connect( );
}
这是NwClient 类中的connect方法,
public void connect( ) throws Exception{ System.out.println("Client.connect() is running");
socket = new Socket( host,port); System.out.println("new Client Socket:"); oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream( socket.getInputStream() );
dis = new DataInputStream( socket.getInputStream() );
dos = new DataOutputStream( socket.getOutputStream( ) ); connected = true;
System.out.println(" Connect established");
}输出如下:
new RemoteSingly:
Client is connecting Server:
NwClient's connect() is running:
(这里停了一会没反应了,直接跳回命令行)C:\JAVA\Linknet>也就是在 建立客户端程序的Socket的时候程序被终止了不知道这个问题是什么地方造成的,求大神帮忙啊
编译是没问题的,运行的时候也没有异常抛出的提示但是就在执行 socket = new Socket( host,port)这个语句时停了一小会,下面的输出语句也没有执行,程序自动终止了
main函数中有这个语句:
Singly s2 = new RemoteSingly("Host", 4321);
调用NwClient对象的connect函数的是RemoteSingly构造函数
这个是RemoteSingly的构造函数, ( 成员变量 private NwClient nc = null;)public RemoteSingly( String host, int port )throws Exception{ System.out.println(" new RemoteSingly:");
this.nc = new NwClient( host, port); System.out.println(" Client is connecting Server ");
nc.connect( );
}
这是NwClient 类中的connect方法,
public void connect( ) throws Exception{ System.out.println("Client.connect() is running");
socket = new Socket( host,port); System.out.println("new Client Socket:"); oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream( socket.getInputStream() );
dis = new DataInputStream( socket.getInputStream() );
dos = new DataOutputStream( socket.getOutputStream( ) ); connected = true;
System.out.println(" Connect established");
}输出如下:
new RemoteSingly:
Client is connecting Server:
NwClient's connect() is running:
(这里停了一会没反应了,直接跳回命令行)C:\JAVA\Linknet>也就是在 建立客户端程序的Socket的时候程序被终止了不知道这个问题是什么地方造成的,求大神帮忙啊
根据程序打印结果来看
socket = new Socket( host,port);
这里可能出异常了
实在是郁闷...