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

CodePudding user response:

reference 1st floor dataxdata 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 beforehand, while waiting for the client access to the assigned 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 to implement


Now intends to use the completion port to fix, because he is web server, web submitted data is forwarded to the server again, is a lot of judgment is a bit fuzzy, beginners said glum, thanked friend answer!

CodePudding user response:

refer to the second floor cool_sec response:
reference 1st floor dataxdata reply: 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 beforehand, while waiting for the client access to the assigned 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 to implement the

Now intends to use the completion port...
,,,, I thought it was my post sent you a wrong, see this elder brothers do forwarding,

CodePudding user response:

1, do service handles the repeater, for each connection open thread
2, registration processing, pairs of connected to register, that is a client and a server, do a registration

CodePudding user response:

CB with Indy control can support multithreading, when the connection automatically after open a thread for you. Don't know what kind of software you need to do. Such as IM - the easiest way to get work client & gt; Server (is the repeater, can forward anything, documents, pictures, text) - & gt; The client.
  • Related