Created
November 4, 2015 19:17
-
-
Save peter279k/b25cc517cf0187954d2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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