Question: No chat gpt #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main ( ) { int MySocket,

No chat gpt #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int MySocket, portNum, nBytes;
char input_buffer[1024];
char received_msg[1024];
char port_string[10];
char ip_string[17];
struct sockaddr_in serverAddr;
socklen_t addr_size;
int i =0;
std::string Query[]={
"car",
"elephant",
"flower",
"monkey",
"garbage"};
/*Create UDP socket*/
MySocket = socket(AF_INET, SOCK_DGRAM, 0);
/*Configure settings in address struct*/
serverAddr.sin_family = AF_INET;
portNum = atoi("12345");
serverAddr.sin_port = htons(portNum);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
/*Initialize size variable to be used later on*/
addr_size = sizeof serverAddr;
srand(time(NULL));
for (int count =0; count 10; count++)
{
i = rand()%5;
strcpy(input_buffer, Query[i].c_str());
nBytes = strlen(input_buffer)+1;
sendto(MySocket, input_buffer, nBytes, 0,(struct sockaddr *)&serverAddr, addr_size);
cout "Sent \e[31m" input_buffer "\e[0m to server...
";
nBytes = recvfrom(MySocket, received_msg,1024,0, NULL, NULL);
cout "Received from server: \e[34m" received_msg "\e[0m" endl;
sleep(1);
memset(input_buffer, '\0', sizeof input_buffer);
}
strcpy(input_buffer, "Quit!");
nBytes = strlen(input_buffer)+1;
sendto(MySocket, input_buffer, nBytes, 0,(struct sockaddr *)&serverAddr, addr_size);
return 0;
}In this problem you will create a Test1_Server program that will do the following:
The Test1_Client will contact server on port 12345.
When received "car", the server will send "fast" to the client.
When received "flower", the server will send "beautiful" to the client.
When received "elephant", the server will send "mouse" to the client.
When received "monkey", the server will send "banana" to the client.
When received "Quit!", the server will terminate.
When received something the server cannot recognize, the server will send "what?" to the client.
Please downlad (right click and save) the attached Test_Client code and compile it on your Ubuntu. Do not change the code.
You will create a server code with C++ in VSCode. Compress your project folder and upload to here. Sample run of client and server:In this problem you will create a Test1_Server program that will do the following:
The Test1_Client will contact server on port 12345.
When received "car", the server will send "fast" to the client.
When received "flower", the server will send "beautiful" to the client.
When received "elephant", the server will send "mouse" to the client.
When received "monkey", the server will send "banana" to the client.
When received "Quit!", the server will terminate.
When received something the server cannot recognize, the server will send "what?" to the client.
Please downlad (right click and save) the attached Test_Client code and compile it on your Ubuntu. Do not change the code.
You will create a server code with C++ in VSCode. Compress your project folder and upload to here. Sample run of client and server:
 No chat gpt #include #include #include #include #include #include #include #include

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!