Order Now  +1 678 648 4277 

Reverse-echo-server and client Assignment Help

We boast of a talented team of C++ homework experts and Linux veterans who are at your service round the clock. Get in touch with us immediately if you need reverse-echo-server and client assignment help. At an affordable price, our tutors will custom-write your solution from scratch. All the solutions prepared by our reverse-echo-server and client homework helpers are in line with the instructions provided by the student. You should not waste time wondering, “who can do mu reverse-echo-server and client project?” Contact us with your assignment now.

Table Of Contents
  • Writing a Server and Client Socket Program
  • Reverse echo server
  • Echo Client
  • Programming environment
  • Reverse-Echo Server Code

Writing a Server and Client Socket Program

In this programming assignment, you are going to build a simple reverse echo server and a client using a TCP socket. The server and client should run at different machines.
Reverse-echo-server and client Assignment Help

Reverse echo server

A reverse echo server receives a message from a client over a TCP socket and replies the same message back to the source in reverse order. For example, if a server gets a message “Hello Jim” from a client, then the reverse echo server sends back the message “miJ olloeH” to the client.
The server program should be terminated if it gets “fin” message from a client after it replies “nif” message to the client.
The reverse echo server is stared by the following command line:
Prompt> my-reverse-echo-server [port-number]
For example, if your reverse echo server begins by a user at csci-gnode-01.ucdever.pvt machine, then you can launch your reserver eco server by a command line:
csci-gnode-01>my-reverse-echo-server 5123
Notes:
• You must use the hostname of the machine, but you can use the fixed socket port number.
• Please use port number over 5000+your last 4 digits of your std-id to avoid possible confliction of port-number.
• PLEASE DO NOT USE a string library for reversing string(“strrev()”). Develop string reverse function by yourself.

Echo Client

An echo client gets a message from a user and sends the message to the connected reverse echo server. When the reversed message arrives from the server, it displays the message to the users.
Suppose a user wants to stop the client program, the user types “fin” to the client. The client sends the message to the reverse echo server and waits for the message “nif” from the server. If the client gets the message “nif”, it terminates itself with displaying “nif” message.
Your echo client is stared by the following command line:
Prompt> my-echo-client [hostname of the machine where my reverse echo server is running] [port- number]
For example, if your echo server is running at csci-gnode-02.ucdenver.pvt machine,
csci-gnode-02>my-echo-client csci-gnode-01 5123

Programming environment

• All programs have to be written C or C++ and run on Linux like platform.
• Your program will be tested on csegrid cluster machine, and you must make sure your programs (both server and client) run on “csegrid.ucdenver.pvt” cluster.
• All connections between a server and clients should be TCP/IP sockets.
• A server and client should run on different machines.
o There are four nodes in csegrid.ucdenver.pvt cluster. Once you connect “csegrid-ucdenver.pvt” via Campus VPN, and you will be logged into one of the following four machines.
o You can use one of the following four machines as your server machine and another machine as your client machine. Four machines’ hostnames are:
①. csci-gnode-01.ucdenver.pvt
②. csci-gnode-02.ucdenver.pvt
③. csci-gnode-03.ucdenver.pvt
④. csci-gnode-04.ucdenver.pvt
Required Skills
Everyone is expected to know the following skills and knowledge in order to complete this programming assignment.
• TCP/IP Socket programming
• Understanding Linux/Unix like Operating System
• Creating/invoking processes in Linux/Unix like environment
• Makefile
• C or C++
Deliverables
The deliverables for this assignment include the following files:
1) Written Code for Server and Client program (Source code only)
2) Makefile
3) Readme: A short description of your programs includes: the names of created executable images that will be created after run your makefile, how to run your programs. In addition, you should specify your execution environments, such as type of OS with version number, compiler, etc.

Reverse-Echo Server Code

#include
#include
#include
#include
#include
#include
#define MSG_SIZE 100
/* reverse a message */
void reverse(char *msg, char *rev)
{
    int i, l;
    l = strlen(msg);
    for (i = 0; i < l; i++)
        rev[i] = msg[l - i - 1];
}
int main(int argc, char **argv)
{
    int server_sock;
    int server_port;
    int client_sock;
    unsigned int len;
    struct sockaddr_in server_addr;
    struct sockaddr_in client_addr;
    char message[MSG_SIZE], revmsg[MSG_SIZE];
    int size;
    if (argc != 2)
    {
        printf("Usage:\n %s \n", argv[0]);
        return 0;
    }
    server_port = atoi(argv[1]); /* get port number from command line */
    printf("Starting server...\n");
    /* create socket for the server */
    server_sock = socket(AF_INET, SOCK_STREAM, 0);
    if (server_sock == -1)
    {
        fprintf(stderr, "Error creating server socket\n");
        exit(1);
    }
    memset(&server_addr, 0, sizeof(server_addr)); /* initialize socket to zero */
    server_addr.sin_family = AF_INET; /* set connection type to TCP/IP */
    server_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* set server address to any interface */
    server_addr.sin_port = htons(server_port); /* set server port number */
    /* bind socket to address*/
    if (bind(server_sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) < 0)
    {
        fprintf(stderr, "Error binding server socket\n");
        exit(1);
    }
    printf("Waiting for connections...\n");
    /* listen for client connections */
    if (listen(server_sock, 5) < 0)
    {
        fprintf(stderr, "Error while listening for connections\n");
        exit(1);
    }
    len = sizeof(struct sockaddr_in);
    /* accept connection */
    client_sock = accept(server_sock, (struct sockaddr *)&client_addr, &len);
    if (client_sock == -1)
    {
        fprintf(stderr, "Error accepting client\n");
        exit(1);
    }
    printf("\nClient connected...\n");
    while (1)
    {
        size = recv(client_sock, message, MSG_SIZE, 0);
        message[size] = 0;
        reverse(message, revmsg); /* reverse the message */
        send(client_sock, revmsg, size, 0); /* echo reversed message */
        if (!strcmp(message, "fin")) /* if the message is fin, end */
            break;
    }
    /* closing socket */
    close(client_sock);
    close(server_sock);
    printf("Terminating server...\n");
    return 0;
}
Echo-Client
#include
#include
#include
#include
#include
#include
#include
#define MSG_SIZE 100
int main(int argc, char **argv)
{
    char *server_name;
    int server_port;
    int client_sock;
    struct sockaddr_in server_addr;
    struct hostent *host;
    char message[MSG_SIZE];
    int size;
    if (argc != 3)
    {
        printf("Usage:\n %s \n", argv[0]);
        return 0;
    }
    server_name = argv[1];
    server_port = atoi(argv[2]); /* get port number from command line */
    client_sock = socket(AF_INET, SOCK_STREAM, 0);
    if (client_sock == -1)
    {
        fprintf(stderr, "Error creating client socket\n");
        exit(1);
    }
    memset(&server_addr, 0, sizeof(server_addr)); /* initialize socket to zero */
    server_addr.sin_family = AF_INET; /* set connection type to TCP/IP */
    server_addr.sin_port = htons(server_port); /* set server port number */
    host = gethostbyname(server_name); /* get host structure using server name */
    if (host == NULL)
    {
        fprintf(stderr, "Error getting the server address\n");
        exit(1);
    }
    /* copy first found address to structure */
    memmove(&server_addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);
    /* connect to server */
    if (connect(client_sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
        fprintf(stderr, "Error connecting to server\n");
        exit(1);
    }
    while (1)
    {
        printf("Message to send: ");
        fgets(message, MSG_SIZE, stdin);
        message[strlen(message) - 1] = 0;
        send(client_sock, message, strlen(message), 0); /* send message */
        size = recv(client_sock, message, MSG_SIZE, 0); /* receive echo */
        message[size] = 0;
        printf("Echoed message: %s\n", message);
        if (!strcmp(message, "nif")) /* if the echoed message is nif, end */
            break;
    }
    /* closing socket */
    close(client_sock);
    return 0;
}