IPGlobalProperties.GetIPGlobalProperties

2

I wrote a test app to get all active ports on my network. Did some searching and found this was the easiest way. So I tried it and it work just fine. I then wrote another socket app with a sever and client side. It's pretty basic, has a create sever, join server and refresh button to get the active servers. The only time this method gets called is when you press the refresh button. If I open up the application 3 or more times and create a server with connected clients by the 4th one this method starts giving me this (Unknown error (0xc0000001)) error. Any idea why this could happen? Funny thing is I never get this on the initial application, the one I opened first. I don't know if somehow it get's a lock on this or something.

The exception gets thrown at this line:

IPEndPoint[] endPoints = properties.GetActiveTcpListeners();

Here's the method, it returns an object of List for all ports within a min and max range.

public static List<UserLocalSettings> ShowActiveTcpListeners(int min, int max)
{
    List<UserLocalSettings> res = new List<UserLocalSettings>();
    try
    {
        IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
        IPEndPoint[] endPoints = properties.GetActiveTcpListeners();
        foreach (IPEndPoint e in endPoints)
        {
            if (e.Port > (min - 1) && e.Port < (max + 1))
            {
                UserLocalSettings tmpClnt = new UserLocalSettings();
                tmpClnt.player_ip = e.Address.ToString();
                tmpClnt.player_port = e.Port;
                tmpClnt.computer_name = Dns.GetHostEntry(e.Address).HostName;
                res.Add(tmpClnt);
            }
        }

    }
    catch (Exception ex1)
    {
    }
    return res;
}

Here's a screen print of the exception:

http://i.stack.imgur.com/bttxk.gif

c#
asked on Stack Overflow Feb 20, 2013 by user2090374 • edited Jan 10, 2014 by Mohsen Safari

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0