1描述问题
我在做一个简单的练习项目,要学习掌握socket的基本用法。
我的问题出现在demo(客户端)的java文件里,虽然我按照老师的讲解写了代码,
//socket("IP地址",端口号);
Socket s=new Socket("192.168.43.224",8888);
但是程序出现了异常
2贴上相关代码
public static void main(String[] args) throws Exception {
Socket s=new Socket("192.168.43.224",8888);
while (true){
System.out.println("请选择操作");
System.out.println("1增加2删除3更改4查询5退出");
Scanner sc=new Scanner(System.in);
int choose=sc.nextInt();
switch (choose){
case 1:
add(s);
break;
case 2:break;
case 3:break;
case 4:break;
case 5:s.close();return;
}
}
}
3报错信息
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.connect0(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at java.base/java.net.Socket.connect(Socket.java:540)
at java.base/java.net.Socket.(Socket.java:436)
at java.base/java.net.Socket.(Socket.java:213)
at homework.itheima.client.Demo.main(Demo.java:11)
4尝试过的方法
搜索了“java.net.ConnectException: Connection refused: connect”,但是
还是无从下手
5相关截图