Home > Back-end > C two-way forward how to design, comment!
C two-way forward how to design, comment!
Time:10-27
Younger brother interns, beginner c + + network programming, so I want to ask next multithreading two-way repeater how to write, and a few problems, The model is as follows, sClient [client] <- & gt; STran [repeater] <- & gt; SServer/server Is the client to connect to the repeater, send data to the repeater, the repeater pass data to the server, and then returned by the server data, then passed on to the client in this way, I now of the solution is to monitor a port, when the customer to connect, create a thread sends the socket in the past, but the second time when the client will create a thread to send data, so there are many places don't understand, now consult everybody can give me a full maturity model or train of thought, can let the repeater bidirectional forwarding and multi-threaded support N customer,,, I consult modestly, online etc.!!
CodePudding user response:
If the client number of concurrent access is not big, just a client corresponds to a thread, you can create a new thread when the client access, can also create a thread pool in advance and waiting for the client access distribution of a single thread, and other communications to delete or release the thread, the end of the client this way is feasible under the condition of less If the number of concurrent client is very big, such as hundreds or thousands of client access at the same time, consider with the completion port