0

我打开了手机的热点并将计算机连接到热点并使用此代码创建服务器,但 InetAddress 变为“/0.0.0.0”:

 ServerSocket ss = null;
        try {
            ss=  new ServerSocket(4444);

            //texto.append("\n"+ss.getInetAddress());
            Log.d("TcpServer", ss.getInetAddress()+"");
            log= ss.getInetAddress().toString();
            //ss.setSoTimeout(10000);
            //accept connections
            Socket s = ss.accept();
            Log.i("TcpServer", "Receiving");
            //texto.append("\n"+"Receiving");
            BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
            //BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
            //receive a message
            Log.i("TcpServer", in.readLine());
            final String incomingMsg = in.readLine() + System.getProperty("line.separator");
            Log.i("TcpServer", "received: " + incomingMsg);
            runOnUiThread(new Runnable() {
                public void run() {
                  //  texto.append("received: " + incomingMsg);

                }
            });

            s.close();
4

1 回答 1

0

是的。如果只是创建一个套接字,则默认是监听所有网络设备/所有分配的 IP 地址,这通过监听 IP 来体现0.0.0.0

于 2013-08-06T10:06:41.987 回答