我打开了手机的热点并将计算机连接到热点并使用此代码创建服务器,但 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();