title: Is it possible to have active open sockets on multiple network interfaces simultaneously?
body: <h1>The Problem</h1>
  
  <p>Is it possible to have active open sockets on multiple network interfaces simultaneously on Android? I want to send/receive datagrams on wifi and mobile data networks simultaneously (obviously on different sockets). Theoretically nothing should prevent this, IP allows multihomed hosts and from what I see there is at least one App which proves this is possible in practice on Android: <a href="http://speedify.com/" rel="nofollow noreferrer">http://speedify.com/</a></p>
  
  <h1>Things I tried so far</h1>
  
  <h2>Attempt 1</h2>
  
  <p>Use <code>ConnectivityManager.getAllNetworks()</code> to enumerate all networks and then use <code>Network.bindSocket()</code> to bind my socket to a specific network I need. Unfortunately <code>ConnectivityManager.getAllNetworks()</code> only returns an array with one single entry. If wifi is active this entry corresponds to wifi network, if wifi is inactive this entry corresponds to mobile data network. Looks like this function is broken and simply does the same thing as <code>ConnectivityManager.getActiveNetwork()</code>.</p>
  
  <h2>Attempt 2</h2>
  
  <p>Use <code>ConnectivityManager.getAllNetworkInfo()</code> to enumerate all network infos. This correctly returns an array of <code>NetworkInfo</code> which includes wifi and mobile data. Unfortunately I cannot see a way to go from <code>NetworkInfo</code> to <code>Network</code> so that I can then call <code>Network.bindSocket()</code>. Only the reverse mapping is possible from <code>Network</code> to <code>NetworkInfo</code> which is of no use. The documentation also says <code>getAllNetworkInfo()</code> is deprecated in API level 23 and recommends to use <code>getAllNetworks()</code> instead, which unfortunately is not a proper substitute (see Attempt 1 for explanation).</p>
  
  <h2>Attempt 3</h2>
  
  <p>Use <code>NetworkInterface.getNetworkInterfaces()</code> to enumerate all interfaces, then enumerate the local IP addresses so that I can then use <code>InetAddress</code>, create <code>InetSocketAddress</code> and call <code>DatagramSocket.bind()</code>. Again the problem is the enumeration only returns 1 IPv4 address. Depending on whether wifi is active or no I either get my wifi IPv4 address or my mobile data IPv4 address but never both at the same time.</p>
  
  <p>I am stuck and don’t know what else to try. I am sure this must be possible since Speedify obviously does it but I cannot find a way.</p>
  
  <h1>Why I Need This</h1>
  
  <p>The purpose is to access servers which are only accessible via one of the networks but not the other and my tasks does require active simultaneous connections so suggestion like “don’t do it” really won’t help.</p>
  
  <h1>[Update]</h1>
  
  <p>I am not asking about <a href="https://en.wikipedia.org/wiki/Multipath_TCP" rel="nofollow noreferrer">multipath TCP</a>. All I need is <a href="https://en.wikipedia.org/wiki/Multihoming#Host_multihoming" rel="nofollow noreferrer">host multihoming</a> which is a simpler use-case that allows to have several different TCP connections (or UDP datagrams) on different network interfaces, but each connection strictly working through one network interface only.</p>