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 664511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:36:28+00:00 2026-05-13T23:36:28+00:00

void CApplication::SendData( const char pBuffer[] ) { if( pBuffer == NULL ) { Log()->Write(

  • 0
void CApplication::SendData( const char pBuffer[] )
{
    if( pBuffer == NULL )
    {
        Log()->Write( ELogMessageType_ERROR, "Cannot send NULL message.");
        return;
    }
    // calculate the size of that data
    unsigned long messageSize = strlen( pBuffer );

    // fix our byte ordering
    messageSize = htonl( messageSize );

    if( isServer == true )
    {
        for( unsigned int i = ESocket_CLIENT0; i < ESocket_MAX; ++i )
        {
            // send the message size
            if( m_Socket[ i ] > 0 )
            {
                if( send( m_Socket[ i ], (char*)&messageSize, sizeof( messageSize ), 0 ) == SOCKET_ERROR )
                {
                    Log()->Write( ELogMessageType_ERROR, "[Application] Send error: %i to socket %i", WSAGetLastError(), m_Socket[ i ] );
                    continue;
                }

                // fix our message size back to host ordering
                messageSize = ntohl(messageSize);

                // send the actual message
                if( send( m_Socket[ i ], pBuffer, messageSize, 0 ) == SOCKET_ERROR )
                {
                    Log()->Write( ELogMessageType_ERROR, "[Application] Send error: %i to socket %i", WSAGetLastError(), m_Socket[ i ] );
                    continue;
                }

                Log()->Write( ELogMessageType_MESSAGE, "[Application] SEND: %s", pBuffer );
            }
        }
    }
  • 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-05-13T23:36:28+00:00Added an answer on May 13, 2026 at 11:36 pm

    You’re not handling the case where send() sends less data than you’ve asked it to. You need to loop if that is the case, until all data has gone out. You’re also not handling errors in general, if a client has disconnected, send() might return -1 for instance.

    The typical approach is something like::

    for(size_t to_go = messageSize; to_go > 0;)
    {
      int put = send(sock, buf, to_go);
      if(put < 0)
      {
        perror("Socket send() error");
        break;
      }
      buf += put;
      to_go -= put;
    }
    

    This attempts to send the entire remaining message, until all of it has been sent. You will of course need to adapt for your specific variable names, do better error-handling, and so on; please view the above as a sketch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The argmax() method should help. Update (After reading comment) I… May 16, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer Than a SELECT * FROM and afterwards a file_put_contents() Otherwise… May 16, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer The open-source libxml2 engine supports SAX, and has a Pascal… May 16, 2026 at 12:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to send data from a c# application to a c++ application through
I'm using the following code to write data through a named pipe from one
i am developing application which send and receive data between two computers but there
I am trying to send data to DotNetOpenAuth website as described here http://msdn.microsoft.com/en-us/library/debx8sh9.aspx Sender
I have big problem. Lets look on the code below: protected void Application_AuthenticateRequest(object sender,
I am writing C# application that need to print data to POS STAR printer
I am trying to redirect the Console output of a C#/Mono application into a
I'm making a game in C# and I want to display the progress (movements
I'm trying to make a MFC application(client) that connects to a server on (localhost,port
I have to interface with a slightly archaic system that doesn't use webservices. In

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.