Created
March 17, 2015 20:05
-
-
Save morganwilde/45793215f6f77a447570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include "SocketAddress.h" | |
#include "Socket.h" | |
#include "Request.h" | |
#include "Response.h" | |
#include "Helpers.h" | |
int main(int argc, char **argv) | |
{ | |
// Storage containers for user inputs | |
char * targetAddress = NULL; | |
int targetPort = DEFAULT_PORT; | |
// Extract address/port from user's input | |
interpretCommandLine(argc, argv, &targetAddress, &targetPort); | |
// Create a TCP socket | |
Socket serverSocket = socketCreateFrom(targetAddress, targetPort); | |
// Establish the connection | |
int connectionResult = socketConnectSimple(serverSocket); | |
if (connectionResult < 0) { | |
error("failed to connect to server\n"); | |
} | |
// Create request | |
Request request = requestCreateEmpty(); | |
requestAppendTo(&request, "GET / HTTP/1.1"); | |
requestAppendTo(&request, "Host: wikipedia.org"); | |
requestFinish(&request); | |
// Send request | |
requestSendTo(&request, serverSocket); | |
// Get response | |
Response response = responseGetFrom(serverSocket); | |
// Show response | |
responsePrintRaw(response); | |
// Finish up with the server socket | |
socketClose(serverSocket); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment