Question: Is the following code snippet for a client program or a server program? try { TCPSocket sock ( argv [ 1 ] , 9 4

Is the following code snippet for a client program or a server program?
try {
TCPSocket sock(argv[1],9431); // Connect to the server.
uint32_t val = atoi(argv[2]); // Parse user-suppled value
val = htonl(val); // Convert to network byte order
sock.send(&val, sizeof(val)); // Send to server.
// Read the server's response, convert to local byte order and print it
if (sock.recvFully(&val, sizeof(val))== sizeof(val)){
val = ntohl(val);
cout << "Server Response: "<< val << endl;
}
// Socket is closed when it goes out of scope
} catch(SocketException &e){
cerr << e.what()<< endl;
}
Is the following code snippet for a client program or a server program?
try {
TCPSocket sock(argv[1],9431); // Connect to the server.
uint32_t val = atoi(argv[2]); // Parse user-suppled value
val = htonl(val); // Convert to network byte order
sock.send(&val, sizeof(val)); // Send to server.
// Read the server's response, convert to local byte order and print it
if (sock.recvFully(&val, sizeof(val))== sizeof(val)){
val = ntohl(val);
cout << "Server Response: "<< val << endl;
}
// Socket is closed when it goes out of scope
} catch(SocketException &e){
cerr << e.what()<< endl;
}
server
client

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 Programming Questions!