Home | History | Annotate | Download | only in connect-devices-wirelessly

Lines Matching full:service

1 page.title=Using Network Service Discovery
13 <li><a href="#register">Register Your Service on the Network</a></li>
16 <li><a href="#teardown">Unregister Your Service on Application Close</a></li>
36 <p>Adding Network Service Discovery (NSD) to your app allows your users to
47 <h2 id="register">Register Your Service on the Network</h2>
54 <p>To register your service on the local network, first create a {@link
57 service. </p>
73 <p>This code snippet sets the service name to "NsdChat".
75 local services. Keep in mind that the name must be unique for any service on the
78 them changes the service name automatically, to something like "NsdChat
81 <p>The second parameter sets the service type, specifies which protocol and transport
84 code snippet, the service uses HTTP protocol running over TCP. An application
85 offering a printer service (for instance, a network printer) would set the
86 service type to "_ipp._tcp".</p>
90 authoritative list of service types used by service discovery protocols such as NSD and Bonjour.
92 href="http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml">the
93 IANA list of service names and port numbers</a>.
94 If you intend to use a new service type, you should reserve it by filling out
96 href="http://www.iana.org/form/ports-services">IANA Ports and Service
99 <p>When setting the port for your service, avoid hardcoding it as this
104 service broadcast, there's no need for the port your application uses to be
106 this information from your service broadcast, right before connecting to your
107 service.</p>
127 success or failure of service registration and unregistration.
135 // Save the service name. Android may have changed it in order to
148 // Service has been unregistered. This only happens when you call
160 <p>Now you have all the pieces to register your service. Call the method
165 after the service has been registered must go in the {@link
187 functionality is service discovery. Your application needs to listen to service
191 <p>Service discovery, like service registration, has two steps:
206 // Called as soon as service discovery begins.
209 Log.d(TAG, "Service discovery started");
213 public void onServiceFound(NsdServiceInfo service) {
214 // A service was found! Do something with it.
215 Log.d(TAG, "Service discovery success" + service);
216 if (!service.getServiceType().equals(SERVICE_TYPE)) {
217 // Service type is the string containing the protocol and
218 // transport layer for this service.
219 Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
220 } else if (service.getServiceName().equals(mServiceName)) {
221 // The name of the service tells the user what they'd be
224 } else if (service.getServiceName().contains("NsdChat")){
225 mNsdManager.resolveService(service, mResolveListener);
230 public void onServiceLost(NsdServiceInfo service) {
231 // When the network service is no longer available.
233 Log.e(TAG, "service lost" + service);
259 when a service is found.</p>
261 <li>The service name of the found service is compared to the service
262 name of the local service to determine if the device just picked up its own
264 <li>The service type is checked, to verify it's a type of service your
266 <li>The service name is checked to verify connection to the correct
270 <p>Checking the service name isn't always necessary, and is only relevant if you
273 application wants to connect to a network printer, it's enough to see that the service type
277 NsdManager.DiscoveryListener) discoverServices()}, passing in the service type
288 <p>When your application finds a service on the network to connect to, it
289 must first determine the connection information for that service, using the
321 <p>Once the service is resolved, your application receives detailed
322 service information including an IP address and port number. This is everything
323 you need to create your own network connection to the service.</p>
326 <h2 id="teardown">Unregister Your Service on Application Close</h2>
331 it. Also, service discovery is an expensive operation, and should be stopped
334 to start and stop service broadcast and discovery as appropriate.</p>