[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] SOC Proposal: Networking for Pygame



Has anyone had a look at the enet API?  Enet is used for the cube
engine.  It uses channels of data.

You keep different information in different channels. This way when
you send data you send it to a channel, and not to a client/server. It can simplify your code because you are not worried who you are
sending the data to, just what.


Then you have other code which determines which channels get sent to
which other peers.


#pygame.events.Network(data, channel, lossy) e = pygame.events.Network("hello network.", CHANNEL_CHAT, 0) network.post(e)

for e in pygame.event.get():
   if e.type == NETWORK:
       if e.what == NET_DATA_IN:
           print e.channel
           print e.data
           print e.sequenceid
           print e.peer


You have the discovery & connection functions tell which channels the peers are interested in.

Here's the link for enet.  http://enet.cubik.org/




On 5/8/06, Peter Shinners <pete@xxxxxxxxxxxx> wrote:
On Sun, 2006-05-07 at 20:27 -0700, Brian Fisher wrote:
> Also, having to integrate the packet handling into your main loop
> wouldn't necessarily help you have good design - for some network
> models, it makes a lot more sense to encapsulate the communication

I'd lean towards this design as well. Just make the "pump" style
function also return all the updates since the previous call.

If the API is going to be threaded then using the Pygame/SDL event queue
makes a bit more sense. Make each connection take an event id number to
use. This is still easy enough to use, but avoids id collisions.