On Wed, Jun 20, 2012 at 8:02 PM, Szymon Wróblewski <[email protected]> wrote:
> I focused currently on creating client api and not everything is complete
> yet, but client side could look like this:
> (same code with syntax highlighting: http://pastebin.com/CiypsKpC)
>
> import pygame
> import pygame_network
>
> pygame.init()
> # create connection
> pygame_network.connect('localhost', 10000)
> # connection overlay
> host = pygame_network.client.Host()
> # register new packet type
> # it will call pygame_network.packets.PacketManager.register()
> echo = pygame_network.register('echo', ('user', 'msg'))
> name = raw_input('name: ')

I really hate to see the globals here. Wouldn't it be better to have
it something like this?

connection = pygame_network.connect('localhost', 10000)
connection.register('echo', ('user', 'msg'))

then you can connect to different servers with different protocols at
the same time.
The network events then would have a connection property telling you
from which connection they came.
You can also then close one of the connections independently from others.
You would also probably want a separate 'protocol' object on which you
would register the messages, so
that you can reuse it for several connections.

What do you think?


-- 
Radomir Dopieralski

Reply via email to