Jump to content
  • Advertisement

Archived

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

logout

UDP and winsocket

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

Okay i got some simple UDP stuff up and going... Now i got 2 questions : 1: In order to send back info from the server do i need to bind() a socket on the client side as well ? 2 ( most inportant ) : How can i identyfy witch client that are sending to me ? Right now im doing some magic on the "cli_addr.sin_addr.S_un.S_addr" But whats a smart way of doing this ? *and ensuring that the correct player gets handled as the correct player*

Share this post


Link to post
Share on other sites
Advertisement
yeah i know that but how should i store/find the correct data ?

i am pretty sure a linear seach tru all clients for EVERY packet will be prett slow on the server. ..

Share this post


Link to post
Share on other sites
quote:
Original post by logout
i am pretty sure a linear seach tru all clients for EVERY packet will be prett slow on the server. ..


I used an STL map.

Share this post


Link to post
Share on other sites
Yeah, foofightr''s using a map idea is good enough. You could use a map for address (an unsigned int 32-bit) to client_info (a class object carrying client details) mapping.

Also, you should check out http://www.ecst.csuchico.edu/~beej/guide/net/ to start up with network programming and getting your basic questions answered.

Share this post


Link to post
Share on other sites
I think Synth0id answered your 2nd question. IP address, under connection-less communication, can be used to determine the source. Check the sockaddr* parameter in the recvfrom function.

Hashtables are a collection of key-value pairs where the key is passed through a process (refered to as a hash-function) to generate a "hash" of that key. This generated hash is then used to locate the value within the data structure.

For example, let us assume that your key is "truman" (a key doesn't necessarily have to be a string), a simple hash function could sum up the characters of this string to generate an index into an array. Hence facilitating lookup.

A map could use a hashtable.

Considering your current problem, you can lookup clients (as I said earlier) based on the incoming data's source IP address.

std::map<unsigned int, client_info*> mapClients ;

recvfrom (...) ;
unsigned int addr = extractipaddr (...) ;
client_info *ci = mapClients [addr] ;

lookup recvfrom, and sockaddr_in (if using IPv4).

[edited by - UdayK on September 23, 2003 10:05:46 AM]

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!