Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created November 4, 2015 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/b25cc517cf0187954d2c to your computer and use it in GitHub Desktop.
Save peter279k/b25cc517cf0187954d2c to your computer and use it in GitHub Desktop.
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
@Override
public void onResolveFailed(NsdServiceInfo serviceInfo,
int errorCode) {
// TODO Auto-generated method stub
Log.e(TAG, "Resolve failed" + errorCode);
}
@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "initialized Resolve Succeeded.", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "initialized port: " + serviceInfo.getPort(), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "initialized host address: " + serviceInfo.getHost(), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "initialized service name: " + serviceInfo.getServiceName(), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "initialized service type: " + serviceInfo.getServiceType(), Toast.LENGTH_LONG).show();
portTxt.setText("initialized port: " + serviceInfo.getPort());
hostAddrTxt.setText("initialized host address: " + serviceInfo.getHost());
serviceNameTxt.setText("initialized service name: " + serviceInfo.getServiceName());
serviceTypeTxt.setText("initialized service type: " + serviceInfo.getServiceType());
msgTxt.setText("Server socket run: 6000");
try {
Log.e(TAG, InetAddress.getByName(serviceInfo.getHost().toString()).getHostName());
}
catch(UnknownHostException e) {
Log.e(TAG, "Attempt to resolve host name failed");
}
if (serviceInfo.getServiceName().equals(SERVICE_NAME)) {
Log.d(TAG, "Same IP.");
return;
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment