黑马程序员技术交流社区
标题:
为什么出现的ip会是0.0.0.0
[打印本页]
作者:
微笑=.一瞬间
时间:
2014-4-14 18:29
标题:
为什么出现的ip会是0.0.0.0
程序如下
import java.io.*;
import java.net.*;
class Tc1
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("172.30.81.92",10007);
}
}
class Ts1
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(10007);
Socket s=ss.accept();
String ip=ss.getInetAddress().getHostAddress();
System.out.println(ip);
}
}
172.30.81.92 是本机ip 服务端输出的ip是0.0.0.0是怎么回事?
作者:
lwy0319
时间:
2014-4-14 20:21
import java.io.IOException;
import java.net.*;
public class Ts1 {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress("172.30.81.92", 10007));
System.out.println(ss.getInetAddress().getHostAddress());
}
}
复制代码
你的客户端没有问题
作者:
张稳
时间:
2014-4-14 21:48
import java.io.*;
import java.net.*;
class Tc1
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("172.30.81.92",10007);
}
}
class Ts1
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(10007);
Socket s=ss.accept();
//你写的是ip=ss.getInetAddress().getHostAddress();应该是以下:
String ip=s.getInetAddress().getHostAddress();
System.out.println(ip);
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2