Example usage for android.net.nsd NsdServiceInfo getPort

List of usage examples for android.net.nsd NsdServiceInfo getPort

Introduction

In this page you can find the example usage for android.net.nsd NsdServiceInfo getPort.

Prototype

public int getPort() 

Source Link

Document

Get port number.

Usage

From source file:de.badaix.snapcast.ServerDialogFragment.java

@Override
public void onClick(View v) {
    NsdHelper.getInstance(getContext()).startListening("_snapcast._tcp.", "Snapcast",
            new NsdHelper.NsdHelperListener() {
                @Override/*from   w  w  w  .j  av  a2  s  .  c om*/
                public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(),
                                serviceInfo.getPort() + 1);
                    }
                }
            });
}

From source file:ibp.plugin.nsd.NSDHelper.java

private JSONObject NsdServiceInfoToJSON(NsdServiceInfo info) {
    String name = info.getServiceName();
    String type = info.getServiceType();
    InetAddress host = info.getHost();
    int port = info.getPort();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", name);
    map.put("type", type);
    map.put("address", (host == null) ? "null" : host.getHostAddress());
    map.put("port", (host == null) ? 0 : port);
    JSONObject jsonObj = new JSONObject(map);
    return jsonObj;
}

From source file:de.badaix.snapcast.MainActivity.java

@Override
public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
    Log.d(TAG, "resolved: " + serviceInfo);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(), serviceInfo.getPort() + 1);
        startRemoteControl();//from w w w . ja va2 s  .  com
    }
    NsdHelper.getInstance(this).stopListening();
}