gpt4 book ai didi

java - 通过ip地址连接

转载 作者:行者123 更新时间:2023-12-02 08:00:08 24 4
gpt4 key购买 nike

我正在尝试从文本文件中获取 IP 地址,因此当我使用以下代码时它不起作用..

  System.out.println("get = "+get);     //get is where the ip address is stored after reading from file and it is successfully received as well
Socket client=new Socket(get,5000);

我什至通过 InetAddress 尝试了同样的操作,如下所示..但效果不佳。

  InetAddress ik= InetAddress.getByName(get);
Socket client=new Socket(ik,5000);

但是当我在 get 中手动提供 ip 时,它就可以工作了。我不明白我错在哪里?

  String get="192.168.1.224";

最佳答案

简单地说:

System.out.println("get = "+get.trim());
Socket client=new Socket(get,5000);

关于java - 通过ip地址连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9015315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com