标题几乎总结了我的问题。这个应用程序直到最近才非常完美。现在它只是在调试时挂在doc.Load(stream)
行上。从来没有抛出错误(等待大约5分钟),它只是坐着。任何想法可能是什么问题?
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);
}
}
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);
}