0

Hi i would just like to know how wud u display the client's IP address when the client connects to the server.

This is found on the servers side while waiting for a connect. now i just need to display the client's IP address in this while loop but how:/

while(1)
    {
        textcolor(15);
        cout << "WAITING FOR CONNECTION..." << endl;
        alen = sizeof(cad);
        if((sd2 = accept(sd, (struct sockaddr *)&cad, &alen)) < 0)
        {
            textcolor(12);
            fprintf(stderr, "ACCEPT FAILED\n");
            exit(1);
        }
        s.selectQuery(query1,header);//The select Query will write to the lostLog file
        //will read from lostLog and put all data into the all variable
        ifstream infile("lostLog.doc");
        x="";
        all="";
        while(getline(infile,x))
        {
            all+=x+"\n";
        }
        textcolor(10);
        cout << "A CLIENT HAS CONNECTED TO THE SERVER! " << endl;
        //create the buffer to send over the network
        char buffer[all.size()];
        sprintf(buffer, "%s ", all.c_str());
        send(sd2, buffer,strlen(buffer),0);
        closesocket(sd2);
    }
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by BradenMurphy
0

That structure, &cad, has a member: sin_addr. Use inet_ntoa() to convert it to a string and print it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.