Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

compile and run both files Show your result(screenshot with explanation) ============ server.c #include #include #include #include void error(char *msg) { perror(msg); exit(1); } int main(int

compile and run both files Show your result(screenshot with explanation)

image text in transcribed

image text in transcribed

============

server.c

#include #include #include #include

void error(char *msg) { perror(msg); exit(1); }

int main(int argc, char *argv[]) { int sockfd, newsockfd, portno, clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; int n; if (argc

===========================================

client.c

#include #include #include #include #include

void error(char *msg) { perror(msg); exit(0); }

int main(int argc, char *argv[]) { int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) L. Download the client and server programs into files called server.c and Donaliad he dient and server programs into files called server.c and client.c and compile them into two executables called server and client. The commands would look something like this: gec server.c -o server gec client.c -o client 2.7/ SOCKETS PROGRAMMING 59 Ideally, you should run the client and server on separate hosts on the Internet. You can, if necessary, run the server in one window and the client in another on the same machine. 2. Start the server first by issuing a command to the server with a port number as the argument. This is the port on which the server will listen. Choose a number between 2000 and 65535. If the port is in use, the server will return a message. In that case, pick another number and try again. A typical command line is the following: server 62828 3. Issue a command to start the client, with two arguments: the name of the host on which the server is running and the port number on which the server is listening. So, if the server is on host X, the command line would be: client X 62828 If client and server are on the same machine, then the first argument is localhost. 4. The client will prompt you to enter a message. Subsequently. if there are no errors, the server will display the message on stdout, send an acknowledgmen message to the client and terminate. The client then prints the acknowledy ment message and terminates. tuo nrograms do, we can examine

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions