Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****FOR THIS ASSIGNMENT WE USUSALLY USE VMware or Virtualbox**** UNIX domain clientserver program compilation and run( p. 528) g++ server_ori.cpp -o server g++ client.cxx -o

****FOR THIS ASSIGNMENT WE USUSALLY USE VMware or Virtualbox****

UNIX domain clientserver program compilation and run( p. 528)

g++ server_ori.cpp -o server

g++ client.cxx -o client

./server &

ls -l my_sock

./client

Enter an expression and press enter to process.

------------------------------------------------------------------------------------

///I THINK YOU WILL ALSO NEED THE NEXT:////

/* Server - UNIX domain, connection-oriented */ // #define _GNU_SOURCE #include #include #include #include #include #include // UNIX protocol using namespace std; const char *NAME = "./my_sock"; const int MAX = 1024; void clean_up( int, const char *); // Close socket and remove int main( ) { socklen_t clnt_len; // Length of client address int orig_sock, // Original socket descriptor new_sock; // New socket descriptor from connect static struct sockaddr_un // UNIX addresses to be used clnt_adr, // Client address serv_adr; // Server address static char clnt_buf[MAX], // Message from client pipe_buf[MAX]; // output from bc command FILE *fin; // File for pipe I/O // Generate socket if ((orig_sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { perror("generate error"); return 1; } // Assign address information serv_adr.sun_family = AF_UNIX; strcpy(serv_adr.sun_path, NAME); unlink(NAME); // Remove old copy if present // BIND the address if (bind( orig_sock, (struct sockaddr *) &serv_adr, sizeof(serv_adr.sun_family)+strlen(serv_adr.sun_path)) < 0) { perror("bind error"); clean_up(orig_sock, NAME); return 2; } listen(orig_sock, 1); // LISTEN for connections clnt_len = sizeof(clnt_adr); // ACCEPT connection if ((new_sock = accept( orig_sock, (struct sockaddr *) &clnt_adr, &clnt_len)) < 0) { perror("accept error"); clean_up(orig_sock, NAME); return 3; } // Process 10 requests for (int i = 0; i < 10; i++) { memset(clnt_buf, 0x0, MAX); // Clear client buffer read(new_sock, clnt_buf, sizeof(clnt_buf)); // build command for bc memset(pipe_buf, 0x0, MAX); sprintf(pipe_buf, "echo \'%s\' | bc ", clnt_buf); fin = popen( pipe_buf, "r" ); memset(pipe_buf, 0x0, MAX); read(fileno(fin), pipe_buf, MAX); cout << clnt_buf << " = " << pipe_buf << endl; } close(new_sock); clean_up(orig_sock, NAME); return 0; } void clean_up( int sd, const char *the_file ){ close( sd ); // Close socket unlink( the_file ); // Remove it }

/// AND YOU WOULD ALSO NEED:///

//File : client_ori.cpp

/*

instruction:

(1) Compile each program into an executable.

(2) Place server in background.

(3) Check for presence of the socket.

(4) Run client in the foreground.

On the command line, the presence of the socket can also be confirmed by using the netstat command.

*/ /* Client - UNIX domain, connection-oriented */ // #define _GNU_SOURCE #include #include #include #include #include #include // UNIX protocol using namespace std; const char *NAME = "./my_sock"; const int MAX = 1024; int main( ) { int orig_sock; // Original socket descriptor static struct sockaddr_un serv_adr; // UNIX address of the server process static char buf[MAX]; // Buffer for messages // Generate the SOCKET if ((orig_sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { perror("generate error"); return 1; } serv_adr.sun_family = AF_UNIX; strcpy(serv_adr.sun_path, NAME); // CONNECT if (connect( orig_sock, (struct sockaddr *) &serv_adr, sizeof(serv_adr.sun_family)+strlen(serv_adr.sun_path)) < 0) { perror("connect error"); return 2; } // Prompt for expressions cout << "Enter an expression and press enter to process." << endl; for (int i = 0; i < 10; i++) { memset(buf, 0x0, MAX); cin.getline(buf, MAX-1, ' '); write(orig_sock, buf, sizeof(buf)); } close(orig_sock); return 0; }

///****FOR THIS ASSIGNMENT WE USUSALLY USE VMware or Virtualbox****

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago