Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,all

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.

Or

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)...
C#
HttpListener listener = new HttpListener();
       listener.Prefixes.Add("http://*:8080/");
       listener.Start();
       Console.WriteLine("Listening...");
       for(;;)
       {
           
          HttpListenerContext ctx = listener.GetContext();
          Console.WriteLine("received a request");
          new Thread(new Worker(ctx).ProcessRequest).Start();
       }
    }
class worker{...



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

1 solution

How can it work if you don't try to accept anything? This is not how TcpListener works. Read properly: http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx[^].

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[^].

—SA
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900