Question

To develop a client/server application using TCP sockets and the C programming language that is capable...

To develop a client/server application using TCP sockets and the C programming language that is capable of supporting multiple concurrent service requests from different clients.

PROBLEM

You are to use the Ubuntu operating system as well as both the client and the server programs. You are to modify your server program to process requests from more than one client concurrently. This means different clients may request either the same service or a total different one. The services supported by your server will include:

(1) changing all characters of a text file to uppercase, and

(2) counting the number of a supplied character in a text file.

Your client program will forward service requests to the server stating (1) the kind of service is needed, and (2) all required data necessary for the successful completion of the request. Your client program must use the following syntax for any request to the server where toUpper is the request to change characters to uppercase, and count to return how many times the supplied character is present in the file.

Your-Prompt> toUpper < file.txt >

Your-Prompt> count < char, file.txt >

In the above two examples file.txt is to indicate that a text file is to be suppled as an input parameter. Thechar string is to inform that a character is to be supplied. The information returned to the client, by your server, must be stored in text files with the names fileUpper.txt and fileChar.txt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <process.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
  
// Function designed for chat between client and server.
void func(int sockfd)
{
  
char buff[MAX];
int n;
// infinite loop for chat
for (;;) {
bzero(buff, MAX);
  
// read the message from client and copy it in buffer
read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents
printf("From client: %s\t To client : ", buff);
bzero(buff, MAX);
n = 0;
// copy server message in the buffer
while ((buff[n++] = getchar()) != ' ')
;
  
// and send that buffer to client
write(sockfd, buff, sizeof(buff));
  
// if msg contains "Exit" then server exit and chat ended.
if (strncmp("toUpper", buff, 7) == 0) {
FILE *fp1, *fp2;
char a;
clrscr();

fp1 = fopen("file.txt", "r");
if (fp1 == NULL) {
puts("cannot open this file");
exit(1);
}

fp2 = fopen("fileUpper.txt", "w");
if (fp2 == NULL) {
puts("Not able to open this file");
fclose(fp1);
exit(1);
}

do {
a = fgetc(fp1);
a = toupper(a);
fputc(a, fp2);
} while (a != EOF);

fcloseall();
}
}
else{
FILE *fp;
int charcount = 0;
// Open file in read-only mode
fp = fopen(filename,"r");

// If file opened successfully, then write the string to file
if ( fp )
{
   //Repeat until End Of File character is reached.  
   while ((ch=getc(fp)) != EOF) {
      // Increment character count if NOT new line or space
       if (ch != ' ' && ch != '\n') { ++charcount; }
      
   }
}
  
fprintf(fp,"%d", charcount);
fclose(fp);
}
  
}
  
// Driver function
int main()
{
int sockfd, connfd, len;
struct sockaddr_in servaddr, cli;
  
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
  
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
  
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) {
printf("socket bind failed...\n");
exit(0);
}
else
printf("Socket successfully binded..\n");
  
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0) {
printf("Listen failed...\n");
exit(0);
}
else
printf("Server listening..\n");
len = sizeof(cli);
  
// Accept the data packet from client and verification
connfd = accept(sockfd, (SA*)&cli, &len);
if (connfd < 0) {
printf("server acccept failed...\n");
exit(0);
}
else
printf("server acccept the client...\n");
  
// Function for chatting between client and server
func(connfd);
  
// After chatting close the socket
close(sockfd);
}

Add a comment
Know the answer?
Add Answer to:
To develop a client/server application using TCP sockets and the C programming language that is capable...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or...

    Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or UDP Protocol, the application should do the following: 1. Client reads a line of characters (data) from its keyboard and sends data to server 2. Server receives the data and converts characters to uppercase 3. Server sends modified data to client 4. Client receives modified data and displays line on its screen

  • Using network sockets, write a C program called client that receives three command-line arguments in the...

    Using network sockets, write a C program called client that receives three command-line arguments in the form: client host port file and sends a request to a web server. The command-line arguments are hostRepresents the web server to connect to port Represents the port number where a request is sent. Normally an HTTP request is sent over port 80, but this format allows for custom ports file Represents the file requested from the web server Your program should create a...

  • Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array...

    Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array of struct student_info ( char abc123171 char name [101 double GPA; To simplify the tasks, the server should create a static array of 10 students with random abc123, name, and GPA in the server program. Then the server waits for clients. When a client...

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • Project Description In this project, you will be developing a multithreaded Web server and a simple...

    Project Description In this project, you will be developing a multithreaded Web server and a simple web client. The Web server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer Protocol). Requirements for the Web server The server is able to handle multiple requests concurrently. This means the implementation is multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an HTTP request, the server sets up a TCP connection to...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Write two programs Client and Server

    Given two integer matrices A and B, you are requested to compose a program to perform matrix addition (A + B). Both matrices have N rows and M columns; N > 1, M > 1; You need to divide both (A and B) into four equal (or close to equal) size of submatrices (A0,0, A0,1, A1,0, A1,1 and B0,0, B0,1, B1.0, B1.1)andeachsubmatrixhasdimensioncloseto(N/2)x(M/2). YouneedtocreatefourJavathreads each thread performs a subset of addition on one pair of the submatrices. Example, thread 0 performs addition...

  • Using the programming language of your choice, write a client application which: Connects to a network...

    Using the programming language of your choice, write a client application which: Connects to a network service, then Asks for version information, then Receives the response, then Disconnects and Prints out the response. Detail: The program will take no input from the user. When your program is executed, it should connect to IP address 64.183.98.170 on port 3800. Upon successful connection, send the string: version\n where \n is an end of line marker. The server will respond with a string...

  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT