org.teleal.cling.android
Class AndroidNetworkAddressFactory
java.lang.Object
org.teleal.cling.android.AndroidNetworkAddressFactory
- All Implemented Interfaces:
- NetworkAddressFactory
public class AndroidNetworkAddressFactory
- extends Object
- implements NetworkAddressFactory
Implementation appropriate for Android environment, avoids unavailable methods.
Detects only (one) WiFi network interface on an Android device and its addresses,
ignores all other interfaces. Requires the Android WifiManager
to
ensure that the discovered interface is really the WiFi interface.
- Author:
- Christian Bauer
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
wifiInterface
protected NetworkInterface wifiInterface
bindAddresses
protected List<InetAddress> bindAddresses
AndroidNetworkAddressFactory
public AndroidNetworkAddressFactory(android.net.wifi.WifiManager wifiManager)
throws InitializationException
- Defaults to an ephemeral port.
- Throws:
InitializationException
discoverBindAddresses
protected void discoverBindAddresses()
throws InitializationException
- Throws:
InitializationException
isUsableAddress
protected boolean isUsableAddress(InetAddress address)
getInetAddresses
protected List<InetAddress> getInetAddresses(NetworkInterface networkInterface)
getMulticastGroup
public InetAddress getMulticastGroup()
- Specified by:
getMulticastGroup
in interface NetworkAddressFactory
- Returns:
- The UDP multicast group to join.
getMulticastPort
public int getMulticastPort()
- Specified by:
getMulticastPort
in interface NetworkAddressFactory
- Returns:
- The UDP multicast port to listen on.
getStreamListenPort
public int getStreamListenPort()
- Specified by:
getStreamListenPort
in interface NetworkAddressFactory
- Returns:
- The TCP (HTTP) stream request port to listen on.
getNetworkInterfaces
public NetworkInterface[] getNetworkInterfaces()
- Specified by:
getNetworkInterfaces
in interface NetworkAddressFactory
- Returns:
- The local network interfaces on which multicast groups will be joined.
getBindAddresses
public InetAddress[] getBindAddresses()
- Specified by:
getBindAddresses
in interface NetworkAddressFactory
- Returns:
- The local addresses of the network interfaces bound to
sockets listening for unicast datagrams and TCP requests.
getHardwareAddress
public byte[] getHardwareAddress(InetAddress inetAddress)
- Specified by:
getHardwareAddress
in interface NetworkAddressFactory
- Parameters:
inetAddress
- An address of a local network interface.
- Returns:
- The MAC hardware address of the network interface or
null
if no
hardware address could be obtained.
getBroadcastAddress
public InetAddress getBroadcastAddress(InetAddress inetAddress)
- Specified by:
getBroadcastAddress
in interface NetworkAddressFactory
- Parameters:
inetAddress
- An address of a local network interface.
- Returns:
- The broadcast address of the network (interface) or
null
if no
broadcast address could be obtained.
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
- 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.
getWifiNetworkInterface
public static NetworkInterface getWifiNetworkInterface(android.net.wifi.WifiManager manager)
getEmulatorWifiNetworkInterface
public static NetworkInterface getEmulatorWifiNetworkInterface(android.net.wifi.WifiManager manager)
getRealWifiNetworkInterface
public static NetworkInterface getRealWifiNetworkInterface(android.net.wifi.WifiManager manager)
Copyright © 2011 Teleal GmbH, Switzerland. All Rights Reserved.