Q:

Client/Server: Integer always received as 1 (C-programming)

I'm building a client and a server program that exchanges data over TCP and I'm having trouble sending an ACK-confirmation from the server back to the client when an operation is successfull. I've managed to send a struct with various members from the client to the server, then the server should respond by sending an integer confirming the ID of the struct back to the client.
In server.c I have this function:
int sendACK(int socket, int ack_int){

    int com_result;
    int ACK = htonl(ack_int);

    printf("\n\tSending ACK with value: %i", ack_int);

    com_result = send(socket, &ACK, sizeof(ACK), 0);

    if (com_result == -1) {
        perror("\n\t[ERROR] Send ACK");
        return 0;
    }

    return 1;

}

This function is called by another function in server.c like this:
int ACK = myStruct->ID;
sendACK(socket, ACK);

So, if I have just recieved a struct with ID: 2, the output will be:
Sending ACK with value: 2
In client.c I recieve the ACK like this:
int ACK = 0;
data_size  = sizeof(myStruct.ID);
com_result = read(client_socket, &ACK, data_size);
ACK = ntohl(ACK);

if (com_result == -1) {
    perror("\n\t[ERROR] Read");
} else {
    printf("\n\tRecieved %i of %i bytes", com_result, data_size);
    if (ACK != myStruct.ID) {
        printf("\n\t[ERROR] Invalid ACK (%i).", ACK);
    }
}

But the ACK is always recieved with a value of 1, so the output from client is:
Recieved 4 of 4 bytes
ERROR] Invalid ACK (1).
Why isn't the integer recieved with a value of 2, and how may I fix this?

A:

This is most likely not the problem, but I believe that the 2nd line in your client.c snippet below should be sizeof(ACK).
int ACK = 0;
data_size  = sizeof(ACK); // was: sizeof(myStruct.ID);
com_result = read(client_socket, &ACK, data_size);
ACK = ntohl(ACK);

Also, depending on your data flow, is it possible that you're actually reading correctly and the ACK is the response from a packet which you sent previously?

