diff options
Diffstat (limited to 'CSharp/Ivy/IvyPPC/Ivy.cs')
-rw-r--r-- | CSharp/Ivy/IvyPPC/Ivy.cs | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index 9ab06d7..cc4dd5f 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -397,25 +397,18 @@ namespace IvyBus /// </param>
public void start(string domainbus)
{
- int ndx = 0;
- IPAddress localaddr;
domainbus = getDomain(domainbus);
try
{
- //TODO remove ALL reverse DNS search !!!!
- //TODO possible bug applicationhost = 127.0.0.1 and not IP
- do
- {
- localaddr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[ndx++];
- } while (IPAddress.IsLoopback(localaddr));
app = new MyTcpListener(IPAddress.Any, 0);
- applicationPort = (ushort)((IPEndPoint) app.LocalEndpoint).Port;
- applicationHost = localaddr;
- applicationUniqueId = string.Format("{0}-{1}-{2}",
+ app.Start(); // should be started before getting port
+ applicationHost = getLocalIP();
+ applicationPort = (ushort)((IPEndPoint)app.LocalEndpoint).Port;
+ applicationUniqueId = string.Format("{0}-{1}-{2}",
DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond,
- localaddr.ToString().Replace(".",""),
+ applicationHost.ToString().Replace(".",""),
applicationPort );
- app.Start();
+
}
catch (IOException e)
{
@@ -842,12 +835,33 @@ namespace IvyBus syncControl.Invoke(bind.callback, new object[] { client, arg });
else bind.callback(client, arg);
}
-
+ public static IPAddress getLocalIP()
+ {
+ IPAddress returnaddr = null;
+ //TODO remove ALL reverse DNS search !!!!
+ IPHostEntry ip = Dns.GetHostEntry(Dns.GetHostName());
+ foreach (IPAddress addr in ip.AddressList)
+ {
+ returnaddr = addr;
+ if (IPAddress.IsLoopback(addr)) continue;
+ break;
+ }
+ return returnaddr;
+ }
public static string getDomain(string domainbus)
{
- //TODO pocket PC BUS default ?????
-#if (!PocketPC)
+#if (PocketPC)
+ if (domainbus == null || domainbus.Length == 0)
+ {
+ IPAddress addr = getLocalIP();
+ //TODO Find Braodcast addr from IP;
+ byte[] bytes = addr.GetAddressBytes();
+ bytes[3] = 255;
+ IPAddress bcast = new IPAddress( bytes );
+ domainbus = bcast + ":" + DEFAULT_PORT;
+ }
+#else
if (domainbus == null || domainbus.Length == 0 )
{
domainbus = Environment.GetEnvironmentVariable("IVYBUS");
@@ -857,7 +871,7 @@ namespace IvyBus {
domainbus = Properties.Settings.Default.IvyBus;
}
-#endif
+#endif
if (domainbus == null || domainbus.Length == 0)
domainbus = DEFAULT_DOMAIN;
return domainbus;
|