Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Networking Console
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)...
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 18-Dec-11 19:23pm
Edited 18-Dec-11 19:31pm

1 solution

Rate this: bad
good
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: 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
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 19 Dec 2011
Copyright © CodeProject, 1999-2014
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