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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:46:29+00:00 2026-05-27T11:46:29+00:00

I got a struct for client and server like this: { char type; int

  • 0

I got a struct for client and server like this:

{
   char type;
   int payloadLen;
   char fileName[50];
   int fileIndex;
   int blockOffset;
   int blockLen;
   char streamingData[MAX];
   int h264fileLayer;
 }

in client I recv data like

memset(&data_recevied, 0, sizeof(data_received);
recv(sockfd, (char *)&data_received, sizeof(data_received), 0);

I use this to receive file sent from server,everything works fine for the first leading couples of files,then it broke,I checked the struct when it broke, seems the struct it received is a mess,and fileIndex is way too large,however the client program works fine in Windows with winsock lib,no broken at all.

I think this has something to do with cross-platform,maybe there is something I missed,really could use help here, thanks

  • 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-27T11:46:30+00:00Added an answer on May 27, 2026 at 11:46 am

    It is not good idea to send this kind of structs between programs. With luck it may work.

    There is couple reasons that may cause the problem:

    1. Sender uses different kind of alignments than receiver
    2. Size of int can be different in different systems
    3. Byte order can be different. If both programs runs in PC, then the byte order is not the problem.

    You can try to remove padding (alignments) by using:

    Linux:

    typedef struct 
    {    
        char type;    
        int payloadLen;   
        ...
    }  __attribute__ ((packed)) my_type_t;
    

    Windows:

    #pragma pack(push, 1)
    
    typedef struct 
    {    
        char type;    
        int payloadLen;   
        ...
    } my_type_t;
    
    #pragma pack(pop)
    

    If still problems, then use int32_t (or some other fixed size type) instead of int.

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

Sidebar

Related Questions

I've got a struct defined like this private struct Combinators { public const char
I've got something like: typedef struct Data_s { int field1; int field2; } Data;
I've got a struct that looks like this: public struct MyStruct { public const
Say we've got: struct IsEven { bool operator() (int i) { return i %
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.
I got a simple struct private struct _config { public string name; public int
I got class with template methods that looks at this: struct undefined {}; template<typename
I've got a struct defined in my GLSL like so: struct Rect { float
Got little problem here. I created dynamic array: m_elements = new struct element*[m_number_of_elements]; for(int
I'm getting to grips with RPC in Windows and I've got a basic client/server

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.