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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:59:31+00:00 2026-06-13T22:59:31+00:00

I have a assignment where I am going to implement a score-server for a

  • 0

I have a assignment where I am going to implement a score-server for a game. When a game is done the game is going to send() players name (char *name) and score (int score) to the server for registration, receive(), and the server is going to send back 5 top-scores.

We are going to use Berkeley sockets and C. After some reading and studying of examples I can only find examples that just sends single variables.

write(sd, "Hello World", 12);

char buf[13];
read(sd, buf, 12);
buf[12] = '\0';

What is usual to do ? Send each variable (name and score) is separate write() functions, or create a struct that holds both variables ?

After some reading in Beej’s Guide to Network Programming I come across the problem with byte order(big/little -endian) that I must take in account, this is shown under the section 7.4 Serialization – How to pack data, and is OK except that in all sample code packages they float and single variables, is there any way to pack an entire struct ?

There is also a section 7.5 Sone of Data Encapsulation that takes about creating a protocol that describes how a client and server communicates, for me this looks more like a struct and what I wont to do, but there is no code that shows the principle.


In short: I want to create a stable communication between server and client where I exchange more than just single variables,

  • 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-13T22:59:32+00:00Added an answer on June 13, 2026 at 10:59 pm

    In network communication, there is no concept of variables, or structs. What you are doing is sending a sequence of bytes.

    So the idea of sending structs, is the same as sending a single value: Convert the struct into a sequence of bytes (serialization), write it to the socket, and on the other end, convert the sequence of bytes back into a struct (deserialization).

    So now your problem becomes one of serialization: How do I serialize a struct?

    Which is just the composition of serializing individual values of the struct.

    What is more common

    typically you want to reduce the amount of network traffic. So if you have all the data you want to send upfront, sending it at once is going to be more efficient then manually chunking the data by sending each name/score pair separately.

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

Sidebar

Related Questions

I have an assignment that simulates a dice game. As part of the program,
I am working on an assignment where I have to implement a recursive way
My college course just started going over mongodb and we have an assignment to
I have an assignment that requires us to implement a doubly linked list class.
I have an assignment for my architecture class which to implement a 31 backgammon
I have an FDTD assignment, it's not going well. Whenever I put a source
I have to write a multiplayer pacman game in Java for a university assignment
I have assignment to work on producer and consumer problem by use thread and
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment in which I have to allow a user to plot

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.