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

michelle1010 michelle1010 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
程序代码:
服务器端: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中配置什么。我的防火墙没开着。
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
michelle1010
Eclipse 58,439 成员 49,457 内容