O'Reilly logo

Boost.Asio C++ Network Programming by John Torjo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Passing client to server messages and vice versa

A very important part of a successful client/server application is passing messages back and forth (server to client and client to server). You need to specify what identifies a message. In other words, when reading an incoming message, how do I know it's been fully read?

It's up to you to identify the end of the message (the start of the message is easy, as it's the first byte passed at the end of the previous message), but do make sure it's easy and consistent.

You can:

  • Have fixed-size messages (it's not such a good idea; what will happen when you need to send more data?)
  • Have a specific character that ends the message, such as '\n' or '\0'
  • Specify the message length as the prefix of the message ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required