How to get ip of sender in TCP communicat开发者_如何学Goion in Android.
any one have idea?
In order to receive tcp communication in android, you'll need to have done something like this:
ServerSocket serverSocket = new ServerSocket(port);
Socket clientSocket = serverSocket.accept();
You can then get the address of the client from it's socket by
InetAddress clientAddress = clientSocket.getInetAddress()
To get it in text form, you can then use
String clientAddressString = clientAddress.getHostAddress()
Of course most of these things can throw exceptions, so you'll need to handle them.
精彩评论