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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:37:43+00:00 2026-06-04T23:37:43+00:00

How to send to server 4 bytes int and on server side conver this

  • 0

How to send to server 4 bytes int and on server side conver this buffer to int.

client side:

void send_my_id()
{
 int my_id = 1233;
 char data_to_send[4];
 // how to convert my_id to data_send?
 send(sock, (const char*)data_to_send, 4, 0);
}

server side:

void receive_id()
{
 int client_id;
 char buffer[4];
 recv(client_sock, buffer, 4, 0);
 // how to conver buffer to client_id? it must be 1233;
}
  • 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-04T23:37:44+00:00Added an answer on June 4, 2026 at 11:37 pm

    You may simply cast the address of your int to char* and pass it to send/recv. Note the use of htonl and ntohl to deal with endianness.

    void send_my_id()
    {
     int my_id = 1233;
     int my_net_id = htonl(my_id);
     send(sock, (const char*)&my_net_id, 4, 0);
    }
    
    void receive_id()
    {
     int my_net_id;
     int client_id;
     recv(client_sock, &my_net_id, 4, 0);
     client_id = ntohl(my_net_id);
    }
    

    Note: I preserved the lack of result-checking. In reality, you’ll need extra code to ensure that both send and recv transfer all of the required bytes.

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

Sidebar

Related Questions

This is my Server side code: public void ReceivingData(object sender, EventArgs e) { while
I have a client-server program. I'm sending data like this: private void Sender(string s,TcpClient
I want to send SQL server Dashboard & Health Report to my client on
im want to send notification from my server side (c#) via urbanairship api is
I'm trying to get one side to send an error message to client, but
Server side code: static void Main(string[] args) { static Socket sck; Console.WriteLine(Server Started...); sck
I want to send a message from the server to the client and found
I have written the following code in the server side for a chat client
I have implement the simple TCP server and TCP client classes which can send
Currently I have this problem. Client downloads from server successfully only the 1st time.

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.