This is the client side where it prompts user to enter a string and send it to the server
//send
printf("\nPlaintext : ");
gets(send_data);
send(sock,send_data,strlen(send_data), 0);
//recv
bytes_recieved = recv(sock, recv_data, 1024, 0);
recv_data[bytes_recieved] = '\0';
printf("\nEnciphered text = %s " , recv_data);
fflush(stdout);
close(sock);
And this is the server side.
sin_size = sizeof(struct sockaddr_in);
//accept
connected = accept(sock, (struct sockaddr *)&client_addr,&sin_size);
printf("\n I got a connection from (%s , %d)", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
//recv
bytes_recieved = recv(connected, recv_data, 1024,0);
recv_data[bytes_recieved] = '\0';
printf("\n RECIEVED DATA = %s " , recv_data);
cod = encipher(recv_data, key, 1); //printf("Code: %s\n", cod);
dec = encipher(cod, key, 0); //printf("Back: %s\n", dec);
//send
send(connected, cod, strlen(cod), 0);
send(connected, dec, strlen(dec), 0);
So the thing is, I want to send two strings named 'plaintext' and 'key' from the client. At the server side, I expected it to receive the two strings and process it under encipher() function and then send it back to the client.
How do I send two strings from a client and receive two strings from the server?
gets. Never usegets. It is impossible to use safely and securely.