forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgeClient.cs
More file actions
62 lines (54 loc) · 1.74 KB
/
BridgeClient.cs
File metadata and controls
62 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Net.NetworkInformation;
using PluginCore.Managers;
namespace PluginCore.Bridge
{
public class BridgeClient : ServerSocket
{
#region configuration
static private string ip;
static public string BridgeIP
{
get
{
if (BridgeManager.Settings.CustomIP.Length > 0) return BridgeManager.Settings.CustomIP;
else if (ip == null)
{
ip = DetectIP();
if (ip == null) ip = "invalid";
}
return ip;
}
}
static public int BridgePort { get { return BridgeManager.Settings.Port; } }
static string DetectIP()
{
try
{
string issue = "Unable to find a gateway";
foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
{
issue += "\n" + f.Name + ", " + f.Description;
if (f.OperationalStatus == OperationalStatus.Up)
foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
{
return d.Address.ToString();
}
}
throw new Exception(issue);
}
catch (Exception ex)
{
ErrorManager.AddToLog("Gateway detection", ex);
}
return null;
}
#endregion
public bool Connected { get { return conn != null && conn.Connected; } }
public BridgeClient()
: base(BridgeIP, BridgePort)
{
if (!isInvalid) ConnectClient();
}
}
}