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