Most efficient way for a udp server to find which client it received from?

I'm using boost asio, but all networking api's are practically the same.

I looked everywhere for an example of a udp server that stores and receives from it's clients...

There is this example that is in tcp:
http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/example/cpp11/chat/chat_server.cpp

But tcp has a socket for each client, so every client can have it's own receive loop, and instantly find which client it received from...

Right now, I have this ugly vector of clients, and whenever I receive I have to loop through it to check if it's a client...

I just want an explanation of how actual networked udp videogames handle clients...
Something like this, perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct client_data
{
    // ...
};

std::map< boost::asio::ip::udp::endpoint, client_data > clients ;

void foo( boost::asio::ip::udp::socket& udp_socket )
{
    std::vector<char> buff(1024) ;
    boost::asio::ip::udp::endpoint client_end_point ;

    udp_socket.receive_from( boost::asio::buffer(buff), client_end_point );

    client_data& cd = clients[client_end_point] ; // look up

    // ...
}
Hmm, but is this how large scale games do it :?
I suppose not. It breaks location transparency and IP spoofing is trivial.

My guess would be that a well written game would first demand authentication through a secure channel and return an encrypted authentication cookie. The client would be asked to provide the authentication cookie with every udp request (with mechanisms in place to counter replay attacks and the like).
In my experience, games typically use TCP for most communication and save UDP for realtime things like movement. TCP and UDP are generally used at the same time on the same port.
Topic archived. No new replies allowed.