?
Solved

connection request

Posted on 2000-04-17
7
Medium Priority
?
269 Views
Last Modified: 2013-11-13
when i connected to the net
and i go in my broweser to www.google.com
my broweser make the next request :
GET http://www.google.com/ HTTP... .. .

I want to know to what ip my brower will connect to send this request???

Is it a static ip or depandable on the site i'm connecting to???

How can i get this ip<in a programic way>???

btw i don't use proxy server


0
Comment
Question by:ntdragon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Expert Comment

by:Vile
ID: 2725723
The ip depends on the site you are connecting to. To resolve the ip address from the name string you can use the function gethostbyname() function. There is an example here:
www.lcg.org/sock-faq/detail.php3?id=32

0
 
LVL 8

Accepted Solution

by:
Christoffer Swanström earned 160 total points
ID: 2726467
The HTTP request message looks actually like this:

GET /somedir/page.html HTTP/1.1
....

You don't give the host name in the request, just the directory and file name you want.

The request message is sent to the IP address of the host (for example www.google.com), port 80. As Vile already mentioned, you can use gethostbyname() to translate a host name to an IP address. This works both in UNIX and with WinSock.

You can find quite a nice description of the HTTP protocol at

http://gaia.cs.umass.edu/kurose/apps/http.htm

0
 
LVL 1

Author Comment

by:ntdragon
ID: 2728392
i"ll check the func and then i"ll get back
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:ntdragon
ID: 2728405
another question before i'm checking the func

if i'm geting a file will the func work then

i mean if my request is something like

GET http://www.goole.com/home_page1.gif HTTP1 ... .. .

will this func retrive the servers ip
to who i should connect to send this request???
0
 

Expert Comment

by:Vile
ID: 2729377
You should strip the address off and run that through gethostbyname() and then set up a sockets connection with that server on port 80 (http) then send it the GET request
so the server ip is resolved by gethostbyname() (ie. www.google.com = XXX.XXX.XXX.XXX)
and then connect to that ip with port 80 and send
GET /home_page1.gif HTTP/1.0
0
 
LVL 8

Expert Comment

by:Christoffer Swanström
ID: 2729704
Here's basically what you would do to get a document from an HTTP server:

-load winsock
-create a socket
-resolve the address (i.e. get the IP address corresponding to the server name)
-connect
-send the HTTP request
-receive the document


#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>

#define DEFAULT_BUFFER      2048
#define DEFAULT_MESSAGE     "GET /index.html HTTP/1.0\n\n\0"

char  szServer[128],                  // Server to connect to
      szMessage[1024];                  // Message to send to sever
int   iPort     = 80;                  // Port on server to connect to


int main(int argc, char **argv)
{
    WSADATA                        wsd;
    SOCKET                        sClient;
    char                        szBuffer[DEFAULT_BUFFER];
    int                              ret, i;
    struct sockaddr_in      server;
    struct hostent            *host = NULL;
      
      
      // load winsock

    if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
    {
        printf("Failed to load Winsock library!\n");
        return 1;
    }

    strcpy(szMessage, DEFAULT_MESSAGE);

    //
    // Create the socket, and attempt to connect to the server
    //
    sClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sClient == INVALID_SOCKET)
    {
        printf("socket() failed: %d\n", WSAGetLastError());
        return 1;
    }
    server.sin_family = AF_INET;
    server.sin_port = htons(iPort);

      
      strcpy(szServer, "www.google.com");

    host = gethostbyname(szServer);
    if (host == NULL)
    {
        printf("Unable to resolve server: %s\n", szServer);
        return 1;
    }
    CopyMemory(&server.sin_addr, host->h_addr_list[0], host->h_length);

    if (connect(sClient, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
    {
        printf("connect() failed: %d\n", WSAGetLastError());
        return 1;
    }

    // Send and receive data
    //

    ret = send(sClient, szMessage, strlen(szMessage), 0);
      
      if (ret == SOCKET_ERROR)
        printf("send() failed: %d\n", WSAGetLastError());

      while(1){
            ret = recv(sClient, szBuffer, DEFAULT_BUFFER, 0);
        if (ret == 0)        // Graceful close
            break;
        else if (ret == SOCKET_ERROR)
        {
            printf("recv() failed: %d\n", WSAGetLastError());
            break;
        }

        printf("RECV [%d bytes]: '%s'\n", ret, szBuffer);

      }


      closesocket(sClient);

    WSACleanup();
    return 0;
}
0
 
LVL 1

Author Comment

by:ntdragon
ID: 2730460
Think you all
tosse you helped me alot
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Starting up a Project
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question