发生异常java.net.ConnectException: Connection refused: connect

michelle1010 2007-09-22 11:18:15
程序代码:
服务器端:import java.net.*;
import java.util.*;
import java.io.*;

public class AppServer {

ServerSocket server;
Socket fromClient;
Thread serverThread;

public AppServer(){
System.out.print("聊天服务器启动........");
try{
server=new ServerSocket(1001);
serverThread=new Thread();
serverThread.start();
}catch(Exception e){
System.out.println("不能启动该线程:"+e);
}

}
public static void main(String[] args){

new AppServer();
}
............
........省略
............
}


客户端:public class login impelments ActionListener{
...........
...........
.......创建登录界面

.............
下面是实现事件监听的函数

public void actionPerformed(ActionEvent e1){
JButton button=(JButton)e1.getSource();
if(button.equals(btnCancel)){
this.dispose();
}
else if(button.equals(btnRegister)){
new Register();
this.dispose();
}else{
try{
toServer=new Socket("我的机器名",1001);
streamFromServer=new ObjectInputStream(toServer.getInputStream());
streamToServer=new PrintStream(toServer.getOutputStream());
streamToServer.println("登录信息");
userName=txtUserName.getText();
userPwd=txtUserPwd.getPassword();
strPwd=new String(userPwd);

streamToServer.println(userName+":"+strPwd);
String frmServer=(String)streamFromServer.readObject();
if(frmServer.equals("欢迎")){
new clientInt(userName);
this.dispose();

}else {
showdlg();
}

}catch(Exception e){
System.out.println("发生异常"+e);
}
}

}

public static void main(String[] args){
new Login();
}
}

程序出现异常,发生异常java.net.ConnectException: Connection refused: connect。是1001端口的原因呢,还是因为我没有在eclipse中配置什么。我的防火墙没开着。
...全文
1838 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧