Question: Server, as the name implies, opens a socket server on a particular port and waits for connections. Client, immediately when executed, attempts to open a

Server, as the name implies, opens a socket server on a particular port and waits for connections. Client, immediately when executed, attempts to open a socket connection on the appropriate port. Server must be designed in such a way that an arbitrary number of Clients can be run at the same time. Each one should successfully connect to a socket on the port, and display the same outward behaviour. The user interface of Client can be quite simple. It should just sit there waiting for user input. Once the user has typed a string, it sends the string to the Server over the socket connection. Once the Server receives the transmitted string, it does something to it, and sends it back. It does not metter what the Server does to the string: transform it to upper case, reverse the order of the letters, make every third letter an X, use it to index into a hash table containing the complete works of ShakespeareYou can do whatever you like, as long as the transformation carried out by Server means that the string sent from Server to Client received in reply is: 1. Not exactly the same as the string transmitted TO the Server AND 2. In some way dependent on the string transmitted TO the Server. After the Client receives the string, it prints it and asks for the next one. This process repeats untill the user enters done. When the user enters done, the Client should terminate gracefully. In other words, it should close the socket, clean up after itself, and terminate, without core dumps, unhandled exceptions, and so on. Note that entering Ctrl-C is not considered a graceful form of termination The Server must also terminate gracefully. In this case, you can decide how to do it, either by typing something at the Server, or by sending a special command from a Client, or some other technique.

Modify the following code to achieve that:

Server, as the name implies, opens a socket server on a particular

port and waits for connections. Client, immediately when executed, attempts to open

a socket connection on the appropriate port. Server must be designed in

such a way that an arbitrary number of Clients can be run

at the same time. Each one should successfully connect to a socket

28server.cpp seer.cppmain.cpp No Selection O #include "thread.h" #include #include #include #include #include #include "socketserver.h" using namespace Sync; // This thread handles each client connection class SocketThread : public Thread private: //Reference to our connected socket Socket& socket; // The data we are receiving ByteArray data public: SocketThread (Socket& socket) : socket(socket) th SocketThread() Socket& GetSocket () return socket; virtual long ThreadMain) while(1) try // Wait for data socket.Read (data); // Perform operations on the data std::string data strdata.ToString); std::reverse(data_str.begin), data_str.end)); data - ByteArray (data_str); // Send it back socket.Write(data); catch (...) 28server.cpp seer.cppmain.cpp No Selection O #include "thread.h" #include #include #include #include #include #include "socketserver.h" using namespace Sync; // This thread handles each client connection class SocketThread : public Thread private: //Reference to our connected socket Socket& socket; // The data we are receiving ByteArray data public: SocketThread (Socket& socket) : socket(socket) th SocketThread() Socket& GetSocket () return socket; virtual long ThreadMain) while(1) try // Wait for data socket.Read (data); // Perform operations on the data std::string data strdata.ToString); std::reverse(data_str.begin), data_str.end)); data - ByteArray (data_str); // Send it back socket.Write(data); catch (...)

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!