Process client buffer on tcp server

Since I read a lot of text and code on socket programming, I decided to go like this:

TCP server:

  • Socket Multiplexing
  • asynchronous input-output

I want to be able to handle 800-1200 client connections at the same time. How to handle client buffers? Every single example I read worked with only one single buffer. Why don't people use something like:

typedef struct my_socket_tag { socket sock; char* buffer; } client_data; 

Now I can send the buffer from the receiver stream to the request-stream stream, and reception can continue on another socket when the first client buffer is processed.

Is this a common practice? Am I missing a point?

Please give some tips on how to improve my question next time, thanks!

+4
source share
1 answer

Examples are usually simplified. Scalability is a serious problem, and I suggest that it would be better to start with simpler applications; a thousand client connections may be required, but most applications will require fairly careful development. Socket programming can be difficult.

There are various types of server applications; There is no single approach that would ideally fit all tasks. There are many details to consider (is this a streaming or datagram service?) Are the connections, if any, permanent, does it include many small data transmissions, or several huge transmissions, or many huge transmissions? Et cetera, et so on). This is why you are unlikely to see any common examples in books.

If you choose a thread approach, be careful not to create too many threads; one thread per client is usually (but not always) a bad choice. In some cases, you can process everything in one thread (using async IO) without sacrificing any performance.

Having said that, I would recommend learning C ++ and raising asio (or a similar structure). He takes care of many problems related to scalability, so there is no point in reinventing the wheel.

You can study the book "Applications with the architecture of Open Source Applications" ( freely available ). There are a few examples that may come in handy.

+2
source

All Articles