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

  • Home
  • SEARCH
  • 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 4024314
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:42:24+00:00 2026-05-20T10:42:24+00:00

I am trying to send some text from the client’s end to the server.

  • 0

I am trying to send some text from the client’s end to the server.
I also want to display time stamps,so as to notify the time at which the message was received.
When I try sending the time it sends a blank.However the rest of the string gets displayed.

Here my code for sending from the client’s end:

void ClientSock::OnConnect(int nErrorCode)
{
    // TODO: Add your specialized code here and/or call the base class
    if(nErrorCode)
    {
        AfxMessageBox(_T("Connection Failure."));
        Close();
    }
    else
    {
        time_t clock;
        time(&clock);
        char min[30] = {0};
        char s = ctime_s(min,sizeof(min),&clock);
        char text[100] = {0};
        char user[10] = {"UserName"};
        int n = m_pDlg->GetDlgItemText(ID_REQUEST,text, 100);
        Send(text,n);
        Send(user,sizeof(user));
        Send(min,sizeof(min));
        //m_pDlg->SetDlgItemText(ID_REQUEST,min);
        AfxMessageBox(_T(min));
    }

}

and heres how im printing at the Server’s console:

                  SOCKET client;
            char text[100] = {0};
            char user[10] = {0};
            char min[30] = {0};
            int n,m;
            //(here the server waits for the client and accepts connection requests) 
            client  = accept(server, NULL, NULL);
            //(receiving text from the client)

            n = recv(client, text, 99, 0);          
            recv(client, user, 9, 0);       
            m = recv(client, min, 29, 0);       

            if(n > 0 && m > 0)
            {
                printf("%s:: %s:%s\n",min,user,text);
            }               
            else
                printf("ERROR:Communication Failure.\n");
  • 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-20T10:42:24+00:00Added an answer on May 20, 2026 at 10:42 am

    A tcp connection should be treated as a stream of bytes. You’re treating it as if it was a stream of objects with type information.

    After your 3 Send’s, the bytes that have been transferred would be e.g.

    ABC\0UserName\0\0Time\0 – A total of 19 bytes.

    Then you read 99 bytes, and get all of the data stored into “text”, with nothing left in the stream for your next reads.

    You’ll need to either send the length of the text before the text itself, or you’ll need to read “data” on the receiving end and scan for e.g. a 0-terminator to extract the 3 logical elements of the stream.

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

Sidebar

Related Questions

Hello there im trying to send files using client-server classes in java. For some
I am trying to send some data from a LINQ query in C# to
I'm trying to find the best way to transfer data from server -> client
I am trying to send an email from a site I am building, but
I'm trying to send a SOAP request using SOAPpy as the client. I've found
I'm trying to send some data in an Ajax call to update a record
How would you send long text from jquery to mysql becuase i have been
I am trying to send a small image along with some XML information to
I'm trying to send some data to a PHP script online to submit online
I'm trying to code a C# UDP server. It receives a specific ID from

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.