XmlDocument.Load() is freezing, but not receiving any error

268 views Asked by At

The title pretty much sums up my issue. This application was working pretty perfectly up until recently. Now it is just hanging on the doc.Load(stream) line when debugging. There is never an error thrown (waited about 5 minutes), it just sits. Any ideas what the issue could be?

Listener

private void ReceivePortMessages()
{
    string debug = string.Empty;
    try
    {
        Debug.Print(" >> Starting Server");
        IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
        _TcpListener = new TcpListener(ipAddress, TcpPort); ;
        Debug.Print(string.Format("{0}:{1}", ipAddress.ToString(), TcpPort.ToString()));
        _TcpListener.Start();

        Stopwatch sw = new Stopwatch();
        do
        {
            try
            {
                Debug.Print(" >> Accept connection from client");
                XmlDocument doc = new XmlDocument();
                var tcpClient = _TcpListener.AcceptTcpClient();
                using (var stream = tcpClient.GetStream())
                {
                    doc.Load(stream);
                    XmlElement root = doc.DocumentElement;
                    string rootName = root.Name;
                    RouteInboundXML(rootName, doc.InnerXml, sw);
                    sw.Restart();
                }
            }
            catch (Exception ex)
            {
                Debug.Print("ReceivePortMessages: " + ex.ToString());
                _TcpClient.Close();
                _TcpListener.Stop();
                ErrorLog.Write("XmlProcessing", ex.ToString() + "\r\n" + "DataFromClient: " + debug, "ReceivePortMessages()");
                return;
            }
        } while (true);
    }
}

Send

try
{
    NetworkStream networkStream = client.GetStream();
    byte[] outStream = System.Text.Encoding.ASCII.GetBytes(input + "\0");
    networkStream.Write(outStream, 0, outStream.Length);
    networkStream.Flush();
    byte[] inStream = new byte[10025];
    networkStream.Read(inStream, 0, (int)client.ReceiveBufferSize);
    string returndata = System.Text.Encoding.ASCII.GetString(inStream);
    Textbox_FauxXMLReceive.Text += (returndata) + "\n";
    _requestCount++;
    lblRequestCount.Text = string.Format("Request Count: {0}", _requestCount.ToString());
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString(), "Send Message Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    CloseConnection(client);
}
0

There are 0 answers