且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以从计算机发送请求吗?

更新时间:2022-12-25 12:18:59

如果您不尝试接受任何东西怎么办?这不是TcpListener的工作方式.正确阅读: http://msdn.microsoft.com/en-us/library /system.net.sockets.tcplistener.aspx [TcpClient的接受实例的实例表示远程套接字,以便从网络读取数据/向网络写入数据.
有关更多想法,请参阅我过去的答案:
来自同一端口号的多个客户端 [通过服务器触发的自动更新程序 [如何将ref参数传递给线程 [ ^ ],
启动后更改线程(生产者)的参数a> [ ^ ].

—SA
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