Jump to content
  • Advertisement

Archived

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

Promiscuous Robot

Windows socket woes.

This topic is 6387 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'm fairly new to sockets proggin and I'm having problems making connections. I'm using AF_INET and SO_STREAM sockets. I can't seem to make any connections.. I'm bind()ing to a port, then trying to connect to the localhost (127.0.0.1) on that same port, but accept() never returns a valid socket. And connect() always fails. Instead of trying to just feed everyone loads of code, I'm just looking for maybe some common pitfalls that beginners run into. Secondly, how does one obtain the ip of the local machine (without first making a connection)? One last thing I'm confused about: I set my sockets to be blocking sockets using ioctlsocket(), however my calls to both connect() on the client and accept() on the server don't block at all. -------------------------- I guess this is where most people put a famous quote... "Everything is funnier with monkey's" - Unknown Edited by - Promiscuous Robot on February 19, 2001 6:57:32 PM

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What''s the failure ? Winsock returns the failure condition if you call WSAGetLastError() right after the failure. If its returning with WSANOTINITIALISED (10093) then your not initilizing winsock with WSAStartup before you can perform any winsock opperations. Be sure to call WSACleanup() when your program exits.

Good Luck

-ddn

Share this post


Link to post
Share on other sites
Make sure to check return values from WSAStartup() and all your functions. They will normally tell you exactly what''s wrong.

As for getting the local IP address, you can call GetComputerName() and pass the computer name to gethostbyname().

Share this post


Link to post
Share on other sites
It''s probably better to use gethostname/gethostbyname rather than GetComputerName/gethostbyname. Your code will be more portable and things are just generally less likely to get weird if you stick to a single api set (sockets) rather than mixing them (win32 + sockets).

-Mike

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!