Skip to content

Commit

Permalink
only start HttpServer on WLAN interface type
Browse files Browse the repository at this point in the history
  • Loading branch information
achimmihca committed Apr 11, 2021
1 parent 8a84161 commit c3e0789
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using SimpleHttpServerForUnity;

public class UltraStarPlayHttpServer : HttpServer
Expand All @@ -19,7 +20,7 @@ protected override void Awake()
return;
}

host = IpAddressUtils.GetIpAddress(AddressFamily.IPv4);
host = IpAddressUtils.GetIpAddress(AddressFamily.IPv4, NetworkInterfaceType.Wireless80211);
NoEndpointFoundCallback = SendNoEndpointFound;
StartHttpListener();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace SimpleHttpServerForUnity
{
// https://stackoverflow.com/questions/51975799/how-to-get-ip-address-of-device-in-unity-2018
// https://stackoverflow.com/questions/51975799/how-to-get-ip-address-of-device-in-unity-2018
public class IpAddressUtils
{
public static string GetIpAddress(AddressFamily addressFamily)
public static string GetIpAddress(AddressFamily addressFamily, params NetworkInterfaceType[] networkInterfaceTypes)
{
// Return null if AddressFamily is Ipv6 but Os does not support it
// Return null if AddressFamily is Ipv6 but OS does not support it
if (addressFamily == AddressFamily.IPv6 && !Socket.OSSupportsIPv6)
{
return null;
Expand All @@ -18,11 +20,8 @@ public static string GetIpAddress(AddressFamily addressFamily)
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
NetworkInterfaceType type1 = NetworkInterfaceType.Wireless80211;
NetworkInterfaceType type2 = NetworkInterfaceType.Ethernet;

if ((item.NetworkInterfaceType == type1 || item.NetworkInterfaceType == type2) &&
item.OperationalStatus == OperationalStatus.Up)
if (networkInterfaceTypes.Contains(item.NetworkInterfaceType)
&& item.OperationalStatus == OperationalStatus.Up)
#endif
{
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
Expand Down

0 comments on commit c3e0789

Please sign in to comment.