Thread: view source of html file

  1. #16
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Here's the plain english steps for you.

    1.) Create a method for the person to be able to put in the URL. Either GUI or command-line.
    2.) Convert the input string into the domain name, and the document to pull from the server.
    3.) Convert the URL from the domain name to the IP address.
    4.) Create a Winsock connection to the newfound IP address.
    5.) Send an HTTP "GET" request to the server using the document part of the user input.
    6.) Pipe the output to the screen or to a text file.

    I probally forgot a step, but that's essentially what you need to do.

  2. #17
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    hmm...alright

    that puts it in english for me but could you direct me to a tutorial? or what general topic that is under so i can run a search for it?

  3. #18
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Here's some extra help: Sample Winsock code!

    Code:
    // Port Opener v1.1
    // By: Steven Merrick
    // For educational use only.
    
    // Includes
    
    #include <winsock.h>
    #include <iostream>
    
    // Variables
    
    int port;
    
    // Functions
    
    int Winsock();
    
    // Code
    
    int main()
    {
    	std::cout << "Input port to open: ";
    	std::cin >> port;
    
    	if (port > 65535) // Sanity Check.
    	{
    		std::cout << "\nInvalid port number, quitting.\n" << std::endl;
    		return(0);
    	}
    
    	Winsock(); // Calls Winsock().
    
    	std::cout << "\nPress any key to quit listening." << std::endl; // Program waits in "listening" state here until keypress.
    	std::cin.ignore(2, '\n');
    
    	WSACleanup(); // Cleans up and quits using Winsock. Do NOT forget this.
    
    	return(0);
    }
    
    int Winsock() // Calls the Winsock initalization and opens the port to "listening" state.
    {
    	WSADATA WsaDat; // Not entirely sure, but is required. Appears to just hold our connection state.
    	SOCKET Socket; // What do we want to call our socket?
    	SOCKADDR_IN SockAddr; // Holds the data for our socket: type (sin_family), port (sin_port), and address (sin_addr.s_addr).
    	
    	SockAddr.sin_family = AF_INET;
    	SockAddr.sin_port = htons(port); // Opens the specified port.
    	SockAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Statically set address to bind to, localhost.
    	memset(&(SockAddr.sin_zero), '\0', 8); // Sets the remainder of the SockAddr struct to 0.
    
    	if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0) // If the Winsock v1.1 startup fails..
    	{
    		std::cout << "WSA Initialization failed." << std::endl;
    	}
    	
    	if ((Socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) // If the socket cannot be opened..
    	{
    		std::cout << "Socket creation failed." << std::endl;
    	}
    
    	if (bind(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR) // If the socket cannot be bound to the port..
    	{
    		std::cout << "Attempt to bind failed." << std::endl;
    	}
    
    	listen(Socket, 1); // Sets the socket to listening state on the specified port number.
    
    	return(0);
    }
    This should help get you started as to what you need to do. You might also want to look into send() and recv(), as well as converting the domain name to IP.

    But this should help get you started.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Source file inclusion
    By sh3rpa in forum C++ Programming
    Replies: 7
    Last Post: 10-02-2007, 11:10 AM
  3. Class methods in header or source file?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2007, 05:23 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM