[Solved] socket program to add integers in c


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.

solved socket program to add integers in c