send() and recv() operate on bytes only. You are sending and receiving 3 bytes, but your array is actually sizeof(int) * 3 bytes instead (where sizeof(int) is usually 4 on many platforms). You need to use sizeof() on both ends, eg:
send(sock, &arr, sizeof(arr), 0);
recv(new_socket, &arr1, sizeof(arr1), 0);
However, you also have to pay attention to return values, because send() can send fewer bytes than requested, and recv() can receive fewer bytes than requested. TCP is stream-oriented, not message-oriented. You should be calling send() and recv() each in a loop, re-calling each one until all expected bytes have been sent/received in full, eg:
ssize_t sendAll(int sckt, void *data, size_t length)
{
char *bytes = (char*) data;
while (length > 0)
{
ssize_t sent = send(sckt, bytes, length, 0);
if (sent == -1) return -1;
bytes += sent;
length -= sent;
}
return 0;
}
int arr[3] = {5, 4, 1};
sendAll(sock, &arr, sizeof(arr));
ssize_t recvAll(int sckt, void *data, size_t length)
{
char *bytes = (char*) data;
while (length > 0)
{
ssize_t recvd = recv(sckt, bytes, length, 0);
if (recvd <= 0) return recvd;
bytes += recvd;
length -= recvd;
}
return 1;
}
int arr1[3];
recvAll(new_socket, &arr1, sizeof(arr1));
3is a byte count, not an element count. the two are only synonymous if you're sending simple octets. Chances are you're not even sending one fullint, much less three. Unrelated,&arrcould just bearrin the send call. Won't really matter, but still.send(sock , &arr,sizeof(arr) , 0);sizeofinsendandrecv.