0

I have to design a server which can able to send a same objects to many clients. clients may send some request to the server if it wants to update something in the database.

Things which are confusing:

  1. My server should start the program (where I perform some operation and produce 'results' , this will be send to the client).

  2. My server should listen to the incoming connection from the client, if any it should accept and start sending the ‘results’.

  3. Server should accept as many clients as possible (Not more than 100).

  4. My ‘result' should be secured. I don’t want some one take my ‘result' and see what my program logics look like.

    I thought point 1. is one thread. And point 2. is another thread and it going to create multiple threads within its scope to serve point 3. Point 4 should be taken by my application logic while serialising the 'result' rather the server.

    Is it a bad idea? If so where can i improve?

Thanks

Kid
  • 169
  • 1
  • 19

1 Answers1

2

Putting every connection on a thread is very bad, and is apparently a common mistake that beginners do. Every thread costs about 1 MB of memory, and this will overkill your program for no good reason. I did ask the very same question before, and I got a very good answer. I used boost ASIO, and the server/client project is finished since months, and it's a running project now beautifully.

If you use C++ and SSL (to secure your connection), no one will see your logic, since your programs are compiled. But you have to write your own communication protocol/serialization in that case.

Community
  • 1
  • 1
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • Why should I have to write own communication protocol/ serialisation? I have planned to use Boost serialisation , and TCP/IP. What will go wrong if I use these? – Kid Oct 07 '16 at 15:08
  • @Kid You said you don't want anyone to know the logic you use. That's the only reason. This depends on the level of "secrecy" you wanna pull off. – The Quantum Physicist Oct 07 '16 at 15:10
  • Please forgive me If my question is stupid. Cant I do my encryption using boost ssl, while using tcp/ip?. The reason I am sticking with TCP is, it will take care of packet delivery and its orders. – Kid Oct 07 '16 at 15:45
  • 1
    @Kid Boost::ASIO has an SSL interface. This is what I used. But you have to link it to OpenSSL anyway. If you use Boost::ASIO SSL, you don't have to care about encryption and decryption. Boost does it for you. You only have to provide certificates and keys. – The Quantum Physicist Oct 07 '16 at 15:48