getting client info

This is a discussion on getting client info within the Networking/Device Communication forums, part of the General Programming Boards category; I wish to get the IP address of a client so that I can connect a socket for the client ...

As you can see, I'm trying to return the address in a SOCKADDR structure. I have no idea why this is going wrong. This is more or less just a project to help me learn how to program with winsock, so im not worried about checks on every problem like is port 100 always open. i know that these ports may be in use, but this is just to learn. if anyone has any advice on why i cant seem to get the IP address, please help!! Thanks in advance!!! if you need the client code, I'll be more than happy to post it!!!

I must admit im a bit confused about the logic of your code. Are you just trying to print the IP address of a client that you have accepted a connection to? Or get the Ip address of the client so you can connect to it to start communication?

I have only had a quick look at the code so i could have interpreted it wrong but it seems to me that the server address is binded to a port on your local ip address (you should use INADDR_ANY by the way rather than typing your ip address manually) and waits for the client to connect to it which it then accepts. The server then seems to be trying to connect to the client who just connected to your server. Which is incorrect because once the server accepted the client then communciation has already been made and you dont need to connect to the client.

The way the server should be programmed is:

1. Create the socket
2. Bind the socket
3. Listen on the socket
4. Accept the connection made to the socket
5. Stat sending and receiving data
6. Close the socket