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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:14:44+00:00 2026-06-01T12:14:44+00:00

I would like to send a struct from my client program to a server

  • 0

I would like to send a struct from my client program to a server program (I am writing both the server and the client programs). Also, in case it is important I am writing on a 32-bit OS Linux and both the client and the server will be running on the same systems. Here is my struct:

struct msg_to_server {
    int type_of_msg;
    int type;
    int flag;
    int pid;
    char name[MAX_WORD];
    char client_name[MAX_WORD];
    int child_timeout;
    int numberKilled;
};

I know that if I am sending an int I need to use htonl(int) to convert the unsigned int from host byte order to network byte order, but what do I do in case of a struct?
Any help would be most appreciated.

  • 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-01T12:14:46+00:00Added an answer on June 1, 2026 at 12:14 pm

    If you know you are sending and receiving from the same kind of systems, then there’s no need to convert integers to network byte order. That’s only important if you’re sending between systems with different endianness.

    You can, at a minimum, simply send the bytes of the whole structure over the socket, with no translation step at all.

    // client
    struct msg_to_server msg;
    send(sock, &msg, sizeof(msg), 0);
    
    // server
    struct msg_to_server msg;
    ssize_t n = recv(sock, &msg, sizeof(msg), 0);
    

    However, be aware that if you’re using TCP, then the protocol may not return all the bytes you request on recv(). You might have to call recv() more than once to retrieve all the bytes sent by the client. If you are using UDP, you don’t have to worry about this, but you will have other considerations like unreliable delivery.

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

Sidebar

Related Questions

I would like to send mail from a script on a Windows Server 2003
I would like to send some keystrokes from a C++ program into another window.
I would like to send the output from a command to both STDOUT and
I would like to send a JSON string from the server side to the
I would like to send an email from an application that contains the current
I have a server and a client program (both running on the same machine).
I would like to send some javascript from one file to another in my
I would like to send email from Microsoft Access unattended using VBA. I understand
I would like to send JSON post request to rails 3 server. I have
I would like to send a html string with a GET request like this

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.