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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:45:36+00:00 2026-06-07T16:45:36+00:00

Can any one please tell me how can we send integers from client to

  • 0

Can any one please tell me how can we send integers from client to server and add them
in c.

I was able to send strings successfully but i am not able to figure out how to send
integers.

Please help me out!! The below written code was for reading strings. How can i change it
it to read and add integers.

#define SOCK_PATH "echo_socket"

int main(void)
{

 int s, t, len;
 struct sockaddr_un remote;
 char str[100];
 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
 perror("socket");
 exit(1);
}

 printf("Trying to connect...\n");
 remote.sun_family = AF_UNIX;
 strcpy(remote.sun_path, SOCK_PATH);
 len = strlen(remote.sun_path) + sizeof(remote.sun_family);


 int val=connect(s, (struct sockaddr *)&remote, len);

 if ( val< 0) {
 perror("connect");
 exit(1);
 }

 printf("Connected.\n");

 printf("ENTER THE NUMBERS:");

while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {

if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
}
if ((t=recv(s, str, 100, 0)) > 0) {
str[t] = '\0';
 printf("echo> %s", str);
} else 
{
  if (t < 0) perror("recv");
  else printf("Server closed connection\n");
  exit(1);
 }

}

  • 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-07T16:45:39+00:00Added an answer on June 7, 2026 at 4:45 pm

    Simple:

    int my_int = 1234;
    send(socket, &my_int, sizeof(my_int), 0);
    

    The above code sends the integer as is over the socket. To receive it on the other side:

    int my_int;
    recv(socket, &my_int, sizeof(my_int), 0);
    

    However, be careful if the two programs runs on systems with different byte order.

    Edit: If you worry about platform compatibilities, byte ordering and such, then converting all data to strings on one end and then convert it back on the other, might be the best choice. See e.g. the answer from cnicutar.

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

Sidebar

Related Questions

Can any one please tell me how to set notifications for different values at
Can any one please tell me the difference between target and currenttarget in flex?
can any one please tell me how to get the Google places api key
1)Can Any one please tell me what are the prerequisites have been installed on
can any one please tell me how i can use Mysql with web services
can any one please tell me how to pass a variable as/by value? what
can any one please tell me what are the other ways to build the
Can any one please tell me what is meant by [\x09-\x0d -~] in the
can any one please tell me how to call a webservice repeatedly for every
can any one please tell me whats causing the memory leak. Data_Parser is an

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.