org.fourthline.cling.android
Class AndroidNetworkAddressFactory

java.lang.Object
  extended by org.fourthline.cling.transport.impl.NetworkAddressFactoryImpl
      extended by org.fourthline.cling.android.AndroidNetworkAddressFactory
All Implemented Interfaces:
NetworkAddressFactory

public class AndroidNetworkAddressFactory
extends NetworkAddressFactoryImpl

This factory tries to work around and patch some Android bugs.

Author:
Michael Pujos, Christian Bauer

Field Summary
 
Fields inherited from class org.fourthline.cling.transport.impl.NetworkAddressFactoryImpl
bindAddresses, DEFAULT_TCP_HTTP_LISTEN_PORT, networkInterfaces, streamListenPort, useAddresses, useInterfaces
 
Fields inherited from interface org.fourthline.cling.transport.spi.NetworkAddressFactory
SYSTEM_PROPERTY_NET_ADDRESSES, SYSTEM_PROPERTY_NET_IFACES
 
Constructor Summary
AndroidNetworkAddressFactory(int streamListenPort)
           
 
Method Summary
protected  void discoverNetworkInterfaces()
           
 InetAddress getLocalAddress(NetworkInterface networkInterface, boolean isIPv6, InetAddress remoteAddress)
          Best-effort attempt finding a reachable local address for a given remote host.
protected  boolean isUsableAddress(NetworkInterface networkInterface, InetAddress address)
          Validation of every discovered local address.
protected  boolean requiresNetworkInterface()
           
 
Methods inherited from class org.fourthline.cling.transport.impl.NetworkAddressFactoryImpl
discoverBindAddresses, getAddressNetworkPrefixLength, getBindAddresses, getBindAddressInSubnetOf, getBroadcastAddress, getHardwareAddress, getInetAddresses, getInterfaceAddresses, getMulticastGroup, getMulticastPort, getNetworkInterfaces, getStreamListenPort, hasUsableNetwork, isInSubnet, isUsableNetworkInterface, logInterfaceInformation, logInterfaceInformation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AndroidNetworkAddressFactory

public AndroidNetworkAddressFactory(int streamListenPort)
Method Detail

requiresNetworkInterface

protected boolean requiresNetworkInterface()
Overrides:
requiresNetworkInterface in class NetworkAddressFactoryImpl
Returns:
true (the default) if a MissingNetworkInterfaceException should be thrown

isUsableAddress

protected boolean isUsableAddress(NetworkInterface networkInterface,
                                  InetAddress address)
Description copied from class: NetworkAddressFactoryImpl
Validation of every discovered local address.

Override this method to customize which network addresses are used.

The given implementation ignores addresses which are

Overrides:
isUsableAddress in class NetworkAddressFactoryImpl
Parameters:
networkInterface - The interface to validate.
address - The address of this interface to validate.
Returns:
True if the given address matches all validation criteria.

getLocalAddress

public InetAddress getLocalAddress(NetworkInterface networkInterface,
                                   boolean isIPv6,
                                   InetAddress remoteAddress)
Description copied from interface: NetworkAddressFactory
Best-effort attempt finding a reachable local address for a given remote host.

This method is called whenever a multicast datagram has been received. We need to be able to communicate with the sender using UDP unicast and we need to tell the sender how we are reachable with TCP requests. We need a local address that is in the same subnet as the senders address, that is reachable from the senders point of view.

Specified by:
getLocalAddress in interface NetworkAddressFactory
Overrides:
getLocalAddress in class NetworkAddressFactoryImpl
Parameters:
networkInterface - The network interface to examine.
isIPv6 - True if the given remote address is an IPv6 address.
remoteAddress - The remote address for which to find a local address in the same subnet.
Returns:
A local address that is reachable from the given remote address.

discoverNetworkInterfaces

protected void discoverNetworkInterfaces()
                                  throws InitializationException
Overrides:
discoverNetworkInterfaces in class NetworkAddressFactoryImpl
Throws:
InitializationException


Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.