private void WaitForRequests()
{
this.Dispatcher.Invoke((Action)(() =>
{
m_OutHelper.WriteNewLine("Starting HTTP Listener.");
}));
if (!HttpListener.IsSupported)
{
this.Dispatcher.Invoke((Action)(() =>
{
m_OutHelper.WriteNewLine("Windows XP SP2 or Server 2003 is required to use the HttpListener.");
}));
return;
}
// URI prefixes are required
string[] prefixes = { "http://localhost:8081/resources/" };
if (prefixes == null || prefixes.Length == 0)
throw new ArgumentException("prefixes");
// Create a listener.
HttpListener listener = new HttpListener();
// Add the prefixes.
foreach (string s in prefixes)
{
listener.Prefixes.Add(s);
}
listener.Start();
this.Dispatcher.Invoke((Action)(() =>
{
m_OutHelper.WriteNewLine("Listening...");
}));
while (m_bHttpListenerEnabled)
{
Listen(listener);
}
// You must close the output stream.
listener.Stop();
this.Dispatcher.Invoke((Action)(() =>
{
m_OutHelper.WriteNewLine("Server stopped.");
}));
}