Jump to content
  • Advertisement
Sign in to follow this  
UriKiller

Couple of beginner network questions

This topic is 4765 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

1) Which function retrieves the IP from a domain name, like the IP of www.google.com (I guess it has to do something with DNS). 2) I use the WSAAsyncSelect to handle messages from the WindowProc. Couple things about it: a) Is this a fast way to use when making a multiplayer server and is it better than the normal select? b) Should I return anything from the WindowProc after recieveing a network event? c) If I get a FD_READ message and I do recv and it returns a number which is lesser than the len parameter i gave him, does it mean that this is ALL he got right now inside the socket buffer? (if I call it again would it return -1 and error = WSAEWOULDBLOCK?) d) If I do the following when I get a FD_READ message: recvd = 0; while (recvd != N) { if ((n = recv (sock, data + recvd, N - recvd, 0)) == -1) continue; recvd += n; } Could it make a problem in the network event system because I wasn't expected to read more data than the ammount that came at that moment? anyway, even if not because of that, for some reason I sometimes get a FD_READ message and when I do recv just once he immediatelly return -1 and WSAEWOULDBLOCK is the error so how could it be? Shouldn't he send those messages only when real data arrives? 3) What is the best way to make a recv/send system to handle multiple clients and always get and send data from/to them? and each message has length, msg type, and data, I need to make it availble to even revieve/send one byte each time to each socket (in case of too many clients). 4) I have a server I made and when the client disconnects from it, it sometimes does not get the FD_CLOSE notification message, and only when trying to send something to the socket will return an error and then the server disconnects it. Could it be that the FD_CLOSE message arrives only when the client disconnected in a orderly way like closesocket () and the server doesn't get the message if the clients computer suddenly had exploded?

Share this post


Link to post
Share on other sites
Advertisement
1) gethostbyname
2b) I had a quick look at the docs about this but couldn't see any mention... my guess is that you should return 0 if you handled the message as is usually the case.
2c) Yes, that is all there was in the socket buffer at the time. However some more data may have arrived just after your call to recv, so your next recv might find some data in the buffer again.
2d) Consider this order of events:

You call recv and get data
data arrives, FD_READ posted to the message queue
You call recv and get data
You call recv and get no data, exit your loop

After this, there will be a FD_READ waiting on the message queue, but you have already consumed the data for it.
4) Yes.

(Disclaimer: I have never used WSAAsyncSelect :) )

Share this post


Link to post
Share on other sites
Regarding close notifies: if the other end goes off the network (say, loses power), it can't send you a message saying the connectino is closing, so how would you know? To know for sure, you have to periodically poll the other end, and treat long time-outs as "closed". There's a TCP option called KEEPALIVE that will do it for you, but the default poll interval is usually really long (too long to be useful for games).

I would like to add that WSAAsyncSelect() doesn't scale terribly well, if you're talking thousands (or even hundreds) of connections. For small networked games, it'll probably work well enough.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!