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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:26:45+00:00 2026-06-15T03:26:45+00:00

My server recv() the packet from the client and must display it. Problem is

  • 0

My server recv() the packet from the client and must display it.
Problem is its not displaying the correct data

Here is the code:

    iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
    if (iResult > 0) {
        for ( int i = 0; i < iResult; i++ ) {
            printf( "%02x ", buf[i] );
        }
        printf( "\n" );

    // return "cc cc cc cc cc cc cc cc cc cc"
    // correct return "0A 00 2C 01 29 00 0D 00 B4 01"

When a client connects the server displays cc cc cc cc cc cc cc cc cc cc but that’s not right
It should be 0A 00 2C 01 29 00 0D 00 B4 01


UPDATE

    #define DEFAULT_BUFLEN 512

    char recvbuf[DEFAULT_BUFLEN];
    int recvbuflen = DEFAULT_BUFLEN;

    iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
    if (iResult > 0) {
        for ( int i = 0; i < iResult; i++ ) {
            printf( "%02x ", recvbuf[i] );
        }
        printf( "\n" );

    // return "0A 00 2C 01 23 00 0c 00 ffffffB3 01"
    // correct return "0A 00 2C 01 23 00 0c 00 B3 01"

now there are extra ffffff on the packet, even though i’m only recv 10 bytes.

  • 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-15T03:26:46+00:00Added an answer on June 15, 2026 at 3:26 am

    The data is correct now. What you’re seeing is sign extension when the char value you’re passing to printf is promoted to an int. You can cast the char to an unsigned char and it should display properly.

    for ( int i = 0; i < iResult; i++ ) {
        printf( "%02x ", static_cast<unsigned char>( recvbuf[i] ) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another socket problem. In my client code, I am sending some packet and expectign
i've a problem with send/recv: if the client send two strings, server receive the
Trying to build a proxy server. recv from client -> send to server ->
Server works fine, but the problem is the client doesn't receive anything. server.php <?php
I'm using select() to recv() messages from server, using TCP/IP. When I send() messages
I'm writting a client using socket to receive EEG data from a recording PC
I had written a small client-server code where in I was sending integers and
These code is the Server part of my proxy program, and its function is
I have a client/server connection over TCP using send() and recv() . This is
i've got a problem: sometimes (not regularly) recv returns -1 and errno == EAGAIN

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.