← Back to team overview

lucadestudios team mailing list archive

Re: Network design

 

2009/2/25 Luke Benstead <kazade@xxxxxxxxx>

> Here we go, initial design of the network.. it's possible we can
> implement an RPC interface on top of this, but that might be overkill,
> we'll see how it goes. Let me know what you think (Lee and Dennis that
> includes you, I know you are watching!)
>
>
> OBJECTIVE
>
> The aim of the network API is to provide high level interfaces which
> allow a caller to send and receive data from a remote machine in a
> fast but reliable way.
>
> USE CASES
>
> 1.Sean is programming a server-side logic system for a new super game,
> and after receiving notification that the player has fallen onto some
> spikes he would like to play a sound on the client machine to reflect
> the injury.
> 2.Carsten is programming the client side input code for a new game, he
> would like to notify the physics system on the server that due to the
> extensive gravity of a nearby planet, the player now weighs two metric
> tons.
>
Hehee and thus he is more wide than tall :)

>
> PROPOSED SYNTAX
>
> //server
>
> network_manager* manager = new network_manager();
> server* s = manager->run_server();
> s->listen_for_clients(1);
>
> while(running) {
>        if (s->connected_client_count() > 0) {
>            s->receive_all();
>            packet* p =
> network_manager->spawn_packet<sound_source_packet>();
>
>             //Just showing that sound_source_packet is a subclass of
> packet,
> in reality
>             //spawn_packet would have returned a sound_source_packet*
>
> dynamic_cast<sound_source_packet*>(p)->set_sound(“sounds/pain/ahshit.wav”);
>
>             manager->queue_for_client(0, p); //ready the packet for sending
>             manager->send_queued();   //send the queued packet
>             manager->disconnect_client(0);
>        }
> }
>
> //Client
>
> network_manager* manager = new network_manager();
> client* c = manager->spawn_client(ip_address(127, 0, 0, 1));
>
> int my_id = c->get_allocated_id();
> if (c->is_connected()) {
>        c->receive_all();
>        packet* p = network_manager->spawn_packet<disconnect_packet>();
>        c->queue_for_server(p);
>        c->send_queued();
>
>        assert(c->is_connected() == false);
> }

Okay, so network manager is a factory for server, client and all kinds of
packets. Server and client have a queue for incoming and outgoing packages..
Do the packets received store the IP of the sender? Because for the server
this might be important to know...

Will the packets include traits? So we can handle incoming packages like:

for(std::vector<packet*>::iterator i = c->received_from_server()->begin(); i
!= ...->end(); ++i)
{
      if( i->value_type() == sound_source_packet.value_type())
          sound_manager->handle(i);
}

I don't think we need remote procedure calls then, because these increase
dependencies between the sources. Handling the different packet types just
depends on the headers where these are defined.

Cheers
Carsten

Follow ups

References