MCSharp.Server.doPortCheck C# (CSharp) Method

doPortCheck() public static method

Checks the server port with utorrent to find out if the port is open to the internet
Based on an example given by Fragmer (me at matvei dot org)
public static doPortCheck ( ) : bool
return bool
        public static bool doPortCheck()
        {
            bool portOpen = false;
            try
            {
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.utorrent.com/testport?plain=1&port=" + Properties.ServerPort);
                HttpWebResponse response = (HttpWebResponse) request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(stream);
                        if (reader.ReadLine().StartsWith("ok"))
                        {
                            portOpen = true;
                            Logger.Log("Port " + Properties.ServerPort + " is open!");
                        }
                        else
                        {
                            Logger.Log("Port " + Properties.ServerPort + " is closed. You will need to set up forwarding.", LogType.Warning);
                        }
                    }
                }
                else
                {
                    Logger.Log("Port check did not complete. Please try again.", LogType.Warning);
                }

            }
            catch
            {
                Logger.Log("Could not start listening on port " + Properties.ServerPort + ". Another program may be using the port.", LogType.Warning);
            }
            return portOpen;
        }