Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:09:45+00:00 2026-06-09T22:09:45+00:00

I have a simple server-client model. In which Server sends some encrypted message to

  • 0

I have a simple server-client model. In which Server sends some encrypted message to client. The client then uses the first few characters of the message to decide the processing. The problem is that these messages are getting buffered one after another hence I am loosing the all messages buffered after the first one. Is there a simple way to prevent buffering or tell the send function to flush.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:09:46+00:00Added an answer on June 9, 2026 at 10:09 pm

    Your client has to determine how many bytes should be read for it to process. The server will send one message after another, but the streaming socket allows the bytes to flow as if it is one long message. Your messages need some way to allow the client to know when one ends and the next one begins.

    The easiest way to do that in a streaming socket is to prepend the message with the length of the message. So the client first reads the length, then the client reads that many bytes.

    int send_message (int sock, const void *message, uint32_t len) {
        int r;
        uint32_t mlen = htonl(len);
        r = send(sock, &mlen, 4, 0);
        /* ...error checking... */
        r = send(sock, message, len, 0);
        /* ...error checking... */
        return ok ? len : error;
    }
    
    int recv_message (int sock, void *buf, uint32_t size) {
        int r;
        uint32_t mlen;
        r = recv(sock, &mlen, 4, 0);
        /* ...error checking... */
        mlen = ntohl(len);
        /* ...check buf is large enough... */
        r = recv(sock, buf, mlen, 0);
        /* ...error checking... */
        return ok ? mlen : error;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple question which perhaps someone familiar with Server/Client design &
I have a very simple wcf server. When a client uses an operation contract,
I have coded a single threaded client server model which does following: Server loops
I have a simple client-server app on android. the android service communicates with the
I have a simple client/server setup. The server is in C and the client
Say I have a simple client/server scenario with one method: // client code $client
I have a simple UDP client server written in C++ on Ubuntu 9.10 where
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef
I am trying to learn WCF. I have a simple client and server application
I have built a simple TCP server and need to compare client input with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.