I have a custom TCP proxy Server listening on port 5888(dummy port). The proxy server listens for incoming connections. When the proxy receives HTTP request for certain pages, it should relay it to the main server on port 80.For other page requests the proxy is required to send data to the main Server on port 8081.
The port 80 is used to service the HTML Pages where as the port 8081 is used for streaming data to the clients.
Client --> Proxy(TCP Proxy Server) --> MainServer
Client <-- Proxy(TCP Proxy Server) <-- MainServer
I have implemented the proxy using the Async programming model (BeginXX and EndXX). The proxy is working fine. I have no problem connecting about 10 clients to this proxy.
Now I want to implement threading in the proxy so that I can have more than 300 simultaneous client connections to the Proxy. What is the Best approach to implement this threading considering the Async programming model (Async sockets).
It sounds like you want threading for threading’s sake.
Exactly what problem will be solved by adding extra threads?
Given that the async model calls back into the ThreadPool, you’re already getting “threading” for free. Why do you want more?
You can happily copy from one stream to another in the async callback of the read operation. If you use async for writing too, it’s not going to cause any significant burden to the ThreadPool, and IMO the work is best left there.
Did you consider using async/await for this? If it’s an option, it’s going to make your code several degrees of nesting lighter on the brain.