Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


TCP/IP: Server calls accept(); how do I get the ip of the client?

This topic is 5920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been wading through some docs, and I''m trying to find a quick answer to this. My server calls accept() and gets a client. I want the ip address of the client. This data must be available somewhere. Where is it?

Share this post

Link to post
Share on other sites
When you call accept, you also pass it a pointer to a sockaddr structure. This receives the address of the connecting client, so you can do something like this:

int len = sizeof(SOCKADDR_IN);

s = accept( listen_socket, (sockaddr *)&addr, &len );
cout << "Connection received from: " << inet_ntoa( addr.sin_addr ) << endl;

codeka.com - Just click it.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!