Question

Using network sockets, write a C program called client that receives three command-line arguments in the form: client host po

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

Some boring theory: :P

  • The Hypertext Transfer Protocol (HTTP) is a stateless application layer protocol.
  • In HTTP a client (program) try to establish a connection with other program (Server) to send an HTTP request.
  • If connection is establish between the server and client then server sends an http response in order to http request.In HTTP mainly GET and POST method are used to send the request to the server.

More on GET method :

  • HTTP get request is generally used to get data from the web-server.
  • It has no side effect and it is not supposed to change anything on server. So GET method is idempotent.
  • It can be executed more than once without any side effects.
  • Get method issued when you click a hyperlink or when you type an URL in an address bar and hit the enter key.

HTTP GET Request in C :

  • The basic parameters of GET request are the path of resource and the Host header.
  • The host header can be the domain name or IP address of the target machine, where we are sending the request.

Suppose there is a service:

http://www.google.com/ || http://www.google.com/index.html

When we prepared a GET request for the above URL then it would be look like this.

GET /index.html HTTP/1.1
Host: www.google.com

If the server run only single website on a single IP address then you can use IP address as header like

GET /index.html HTTP/1.1
Host: IP Address/localhost

For conclusion the complete C program is as follow:

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char *argv[]) {

char requestToServer[100]={0};

char requestedResourcePath[]="index.html";

char hostAddress[]="www.google.com";

sprintf(requestToServer, "GET /%s HTTP/1.1\r\nHost: %s\r\nContent-Type: text/plain\r\n\r\n", requestedResourcePath, hostAddress);

printf("Get Request:\n");

printf("%s", requestToServer);

retrn 0;

}

Tip: Pay some attention to theoretical concepts whenever you try any practical implementation.

The above program can be modified to get meta data as well. just ping me if you want it. i did not wants to complicate things that's why i'm giving you simple program.

#StayFocused

Add a comment
Know the answer?
Add Answer to:
Using network sockets, write a C program called client that receives three command-line arguments in the...
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
  • 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...

  • Objective: Create a proxy server that can be connected by a single client and would only...

    Objective: Create a proxy server that can be connected by a single client and would only allow http requests. Requirements: 1. Create a C based client-server architecture using sockets 2. The server should be able to accept and service single client’s http requests 3. The server should be run on cse01.cse.unt.edu machine and the client should be run on cse02.cse.unt.edu machine Procedure: 1. Create a C-based server that can accept single client’s request using sockets 2. The created server should...

  • 1) Write a C program that displays all the command line arguments that appear on the...

    1) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 2) Write a C program which displays the sum of the command line arguments. Hint: use sscanf to convert the decimal arguments (which are strings) to binary numbers that...

  • implement the follwing code using command promp or Eclipse or any other program you are familiar with. keep the name of...

    implement the follwing code using command promp or Eclipse or any other program you are familiar with. keep the name of the classes exatcly the same as requested for testing purpose. please follow each instruction provided below Objective of this assignment o get you famililar with developing and implementing TCP or UDP sockets. What you need to do: I. Implement a simple TCP Client-Server application 2. and analyze round trip time measurements for each of the above applications 3. The...

  • 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...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • 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...

  • 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...

  • Assignment One program will be the update server and the other will be the update client....

    Assignment One program will be the update server and the other will be the update client. Here is how the two programs should interact with each other: Server 1. the server starts up and reads the version number in the data.bin file and stores it in memory. 2. The server binds to a port and awaits connections. Client 1. The client starts up and it will first read the version number found within it's own data.bin file. 2. The client...

  • You are to write a Java program using the following instructions to build a bank-ATM server...

    You are to write a Java program using the following instructions to build a bank-ATM server system with sockets. A bank holds accounts that can have deposits, withdrawals, or retrievals of balance. The bank server provides the account for transactions when a client uses and ATM machine. The ATM asks for the type of transaction and the amount (if needed), then creates a socket connection to the bank to send the transaction for processing. The bank performs the transaction on...

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