Lines Matching full:service
1 page.title=Using Network Service Discovery
17 <li><a href="#register">Register Your Service on the Network</a></li>
20 <li><a href="#teardown">Unregister Your Service on Application Close</a></li>
40 <p>Adding Network Service Discovery (NSD) to your app allows your users to
51 <h2 id="register">Register Your Service on the Network</h2>
58 <p>To register your service on the local network, first create a {@link
61 service. </p>
77 <p>This code snippet sets the service name to "NsdChat".
79 local services. Keep in mind that the name must be unique for any service on the
82 them changes the service name automatically, to something like "NsdChat
85 <p>The second parameter sets the service type, specifies which protocol and transport
88 code snippet, the service uses HTTP protocol running over TCP. An application
89 offering a printer service (for instance, a network printer) would set the
90 service type to "_ipp._tcp".</p>
94 authoritative list of service types used by service discovery protocols such as NSD and Bonjour.
96 href="http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml">the
97 IANA list of service names and port numbers</a>.
98 If you intend to use a new service type, you should reserve it by filling out
100 href="http://www.iana.org/form/ports-services">IANA Ports and Service
103 <p>When setting the port for your service, avoid hardcoding it as this
108 service broadcast, there's no need for the port your application uses to be
110 this information from your service broadcast, right before connecting to your
111 service.</p>
131 success or failure of service registration and unregistration.
139 // Save the service name. Android may have changed it in order to
152 // Service has been unregistered. This only happens when you call
164 <p>Now you have all the pieces to register your service. Call the method
169 after the service has been registered must go in the {@link
191 functionality is service discovery. Your application needs to listen to service
195 <p>Service discovery, like service registration, has two steps:
210 // Called as soon as service discovery begins.
213 Log.d(TAG, "Service discovery started");
217 public void onServiceFound(NsdServiceInfo service) {
218 // A service was found! Do something with it.
219 Log.d(TAG, "Service discovery success" + service);
220 if (!service.getServiceType().equals(SERVICE_TYPE)) {
221 // Service type is the string containing the protocol and
222 // transport layer for this service.
223 Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
224 } else if (service.getServiceName().equals(mServiceName)) {
225 // The name of the service tells the user what they'd be
228 } else if (service.getServiceName().contains("NsdChat")){
229 mNsdManager.resolveService(service, mResolveListener);
234 public void onServiceLost(NsdServiceInfo service) {
235 // When the network service is no longer available.
237 Log.e(TAG, "service lost" + service);
263 when a service is found.</p>
265 <li>The service name of the found service is compared to the service
266 name of the local service to determine if the device just picked up its own
268 <li>The service type is checked, to verify it's a type of service your
270 <li>The service name is checked to verify connection to the correct
274 <p>Checking the service name isn't always necessary, and is only relevant if you
277 application wants to connect to a network printer, it's enough to see that the service type
281 NsdManager.DiscoveryListener) discoverServices()}, passing in the service type
292 <p>When your application finds a service on the network to connect to, it
293 must first determine the connection information for that service, using the
325 <p>Once the service is resolved, your application receives detailed
326 service information including an IP address and port number. This is everything
327 you need to create your own network connection to the service.</p>
330 <h2 id="teardown">Unregister Your Service on Application Close</h2>
335 it. Also, service discovery is an expensive operation, and should be stopped
338 to start and stop service broadcast and discovery as appropriate.</p>