Friends,
I posted earlier my problem but even after trying out a billion things, its not working for me. I'm developing an asynchronous http server (using HttpListener) which needs to receive/process requests simultaneously.
Here is my "synchronous" model - working just fine - which I need to change to asynchronous mode...All suggestions / tips / brickbats are welcome.
Thanks n Regards,
Kunal
namespace HttpListenerLibrary
{
.
. Extra supporting stuff here....
.
public class HttpListenerController
{
private Thread _pump;
private bool _listening = false;
private string _virtualDir;
private string _physicalDir;
private string[] _prefixes;
private HttpListenerWrapper _listener;
public event LogEventHandler _LogEvent;
public LogCallback _logCallback;
internal PersistentXmlEventBuffer _pxeb;
public HttpListenerController(string[] prefixes, string vdir,
string pdir, LogEventHandler leh)
{
_prefixes = prefixes;
_virtualDir = vdir;
_physicalDir = pdir;
_LogEvent += leh;
_logCallback = new LogCallback(LogThis);
_pxeb = new PersistentXmlEventBuffer();
}
public void Start()
{
_listening = true;
_pump = new Thread(new ThreadStart(Pump));
_pump.Start();
}
public void Stop()
{
// some stuff
}
private void Pump()
{
try
{
_listener = (HttpListenerWrapper)ApplicationHost.CreateApplicationHost(
typeof(HttpListenerWrapper), _virtualDir, _physicalDir);
_listener.Configure(_prefixes, _virtualDir, _physicalDir, _LogEvent, _pxeb);
_listener.Start();
while (_listening)
_listener.ProcessRequest();
}
catch (Exception ex)
{
// some stuff
}
}
}
public class HttpListenerWrapper : MarshalByRefObject
{
private HttpListener _listener;
private string _virtualDir;
private string _physicalDir;
public event LogEventHandler _LogEvent;
public LogCallback _logCallback;
internal PersistentXmlEventBuffer _pxeb;
public void Configure(string[] prefixes, string vdir, string pdir,
LogEventHandler leh, PersistentXmlEventBuffer pxeb)
{
_virtualDir = vdir;
_physicalDir = pdir;
_listener = new HttpListener();
_logCallback = new LogCallback(LogThis);
_pxeb = pxeb;
foreach (string prefix in prefixes)
_listener.Prefixes.Add(prefix);
}
public void Start()
{
_listener.Start();
//some more stuff
}
public void Stop()
{
_listener.Stop();
}
public void ProcessRequest()
{
try
{
HttpListenerContext ctx = _listener.GetContext();
string str = ctx.Request.HttpMethod;
HttpListenerWorkerRequest workerRequest =
new HttpListenerWorkerRequest(
ctx,_virtualDir, _physicalDir, _logCallback, _pxeb);
HttpRuntime.ProcessRequest(workerRequest);
}
catch (XmlException xE)
{
LogThis(xE.Message, ColorCode.RcvColor);
}
}
}
public class HttpListenerWorkerRequest : HttpWorkerRequest public HttpListenerWorkerRequest(HttpListenerContext context,
{
private HttpListenerContext _context;
private string _virtualDir;
private string _physicalDir;
public LogCallback _logCallback;
PersistentXmlEventBuffer _pxeb;
string vdir, string pdir,
LogCallback lcb, PersistentXmlEventBuffer pxeb)
{
_context = context;
_virtualDir = vdir;
_physicalDir = pdir;
_logCallback = lcb;
_pxeb = pxeb;
}
// required overrides (abstract)
public override void EndOfRequest()
{
_context.Response.OutputStream.Close();
_context.Response.Close();
}
public override void SendStatus(int statusCode, string statusDescription)
{
_context.Response.StatusCode = statusCode;
_context.Response.StatusDescription = statusDescription;
}
// other overrided functions follow.....
}
}
hi all is this file missing http://local.live.com/JS/VE.js i have programs based on this ,due to t...
By sachin_pithode
Hi Andy:It sounds like you this setup correctly. Anychance the dll is out ofdate and needs to be reb...
By scottallen
Hello guys, first i would like to thank all posts of File Upload here on the forums, with them i cou...
By fhenus
I developed UploadHandler as an implementation of IHttpHandler utilizingHttpWorkerRequest.Also, it i...
By johndoe
I've added a HiddenField control to my page and some javascript to show it'svalue in an aler...
By sklett, 3 Comments
Hello,I wann change the Icon of the address bar of IE,For this i am using this code in the head tag ...
By prashant_victory_hotmail, 6 Comments
I'm tring to learn .NET Remoting, I hope I put this in the right forum. I need to do something real...
By onewisehobbit, 1 Comments
I just finish my first web application. I have a question. Does any one know how can i remove the st...
By drpkrupa, 2 Comments
Hi Alli am installing vs2005 in one of machines which had already got a trialversion of vs2005.i ins...
By senthilvel, 1 Comments