Click here to Skip to main content
13,148,503 members (50,387 online)
Rate this:
Please Sign up or sign in to vote.

I'm developing a proxy server application which cache the most visited & browsed webPage.

I want to capture requests sent from the client computer, then record the urls in a notepad file, then compare between them for the highest visited site & Cache it,
If u have a sample for that, u'll simplify for me the way.


Capture all requests sent from my computer then I will take from it the URL..
The problem that I wrote the following code & no request received yet (Only:listening)...
HttpListener listener = new HttpListener();
          HttpListenerContext ctx = listener.GetContext();
          Console.WriteLine("received a request");
          new Thread(new Worker(ctx).ProcessRequest).Start();
class worker{...

Thank you,
Best Regards...
Posted 18-Dec-11 18:23pm
Updated 18-Dec-11 18:31pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

How can it work if you don't try to accept anything? This is not how TcpListener works. Read properly:[^].

Also, you are trying to heavily abuse threading. You are trying to create more and more threads in a loop! (An infinite loop!). It will lead you nowhere.

You need just two "permanent" network threads: one is accepting new connections, one using accepted sockets or instances of accepted instances of TcpClient representing remote sockets to read/write data from/to network.

For some more ideas, please see my past answers:
Multple clients from same port Number[^],
automatic updater triggered via server[^].

Also, a parametrized thread is a bad thing, doe to type cast. There is a much better way. Please see my solutions with a thread wrapper:
How to pass ref parameter to the thread[^],
change paramters of thread (producer) after it started[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 19 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100