summaryrefslogtreecommitdiff
path: root/CSharp
diff options
context:
space:
mode:
authorfcolin2007-02-01 09:55:36 +0000
committerfcolin2007-02-01 09:55:36 +0000
commit241916bca2c297b78896c453e514a1208e17d416 (patch)
tree0e5f10af80ad1b407476dd807945a69bf352022e /CSharp
parentaecbf057d889e5d5636c10cfe398d42f7f7b2d55 (diff)
downloadivy-csharp-241916bca2c297b78896c453e514a1208e17d416.zip
ivy-csharp-241916bca2c297b78896c453e514a1208e17d416.tar.gz
ivy-csharp-241916bca2c297b78896c453e514a1208e17d416.tar.bz2
ivy-csharp-241916bca2c297b78896c453e514a1208e17d416.tar.xz
Utilisateur : Fcolin Date : 7/02/06 Heure : 16:54 Archivé dans $/CSharp/Ivy/IvyPPC Commentaire: (vss 50)
Diffstat (limited to 'CSharp')
-rw-r--r--CSharp/Ivy/IvyPPC/Ivy.cs48
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;