Q: How to send a string to the server and echo it back? I am creating a program that asks a server for the current time. I want to send my name with the request and get the server to echo my name back with the time. Where do I insert my name?
A snippet of client code

    printf("Client is sending on IP address %s port: %d\n", servIP, servPort);

    /* Send time request to server */
    addrlen = sizeof(struct sockaddr_in);
    sendto(sockfd, buffer, (int)strlen(buffer) + 1, 0, (struct sockaddr *)&server, addrlen);
    printf("Request sent to server\n");
    /* Receive time request from server */
    recvfrom(sockfd, (char *) &current_time, (int) sizeof(current_time), 0, (struct sockaddr *)&server, (socklen_t *)&addrlen);

    /* Print the time received from the server */
    printf("\n The time received from the server:%s\n", ctime(&current_time));

    exit(0);

Snippet of server code
/** Message **/
printf("Server is listening on port: %d\n", PORT);
    printf("Waiting for client request...\n");
    printf("Press CTRL + C to exit\n");

    while(1) {
        addrlen = sizeof(struct sockaddr_in);
        recvfrom(sockfd, buffer,BUFFSIZE, 0,(struct sockaddr *)&client, (socklen_t *)&addrlen);
        current_time = time(NULL);
        sendto(sockfd, (char *) &current_time, (int) sizeof(current_time), 0, (struct sockaddr *)&client, addrlen);
    }
    exit(0);


A: You can put the time in the buffer, after the name.
Server:
printf("Server is listening on port: %d\n", PORT);
printf("Waiting for client request...\n");
printf("Press CTRL + C to exit\n");

while(1) {
    addrlen = sizeof(struct sockaddr_in);
    recvfrom(sockfd, buffer,BUFFSIZE, 0,(struct sockaddr *)&client, (socklen_t *)&addrlen);
    current_time = time(NULL);
    memcpy(buffer + strlen(buffer) + 1, &current_time, sizeof(current_time));
    sendto(sockfd, buffer, strlen(buffer) + 1 + sizeof(current_time), 0, (struct sockaddr *)&client, addrlen);
}
exit(0);

The client puts the name in the buffer:
printf("Client is sending on IP address %s port: %d\n", servIP, servPort);

/* Send time request to server */
addrlen = sizeof(struct sockaddr_in);
strcpy(buffer, name);
sendto(sockfd, buffer, (int)strlen(buffer) + 1, 0, (struct sockaddr *)&server, addrlen);
printf("Request sent to server\n");
/* Receive time request from server */
recvfrom(sockfd, (char *) buffer, sizeof(buffer), 0, (struct sockaddr *)&server, (socklen_t *)&addrlen);
/* Print the name received from the server */
printf("\n The name received from the server:%s\n", buffer);
memcpy(current_time, buffer + strlen(buffer) + 1, sizeof(current_time));
/* Print the time received from the server */
printf("\n The time received from the server:%s\n", ctime(&current_time));

exit(0);

