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

Re: [pygame] SOC Proposal: Networking for Pygame



This simple networking should have few suprises.  As well as allow the
user to not know much about networking.  So I think management of send
buffers should be done automatically.  However allowing inspection of
send buffers would be useful for those who need it.

Hopefully reconnection handling can be done as well.




One other thing to consider... Lossy data is very useful for games.

In lots of games data is not needed to get through.  eg.
 If you have 3 position of player packets that arrive like this:
packet 1
packet 2 *lost*
packet 4
packet 3 *arrives late*

The only packet you care about is the latest one.  You don't care
about old, or lost packets for this type of data.

But should lossy data be considered for simple networking? If so I
think giving the send method, or argument a lossy flag would be good. So that the game can tell networking if it cares about this type of
data. Just using a udp 'connection' would be probably be enough.




On 5/8/06, Bob Ippolito <bob@xxxxxxxxxx> wrote:
This looks pretty good. One thing to note however is that you're
going to need to do the select() in a separate thread if you want it
to be able to wake up the event loop on network events. Depending on
the way you're using the pygame event loop, this might not work out
so well.

Also, what about buffering? If you fill up the send queue it's going
to start dropping data. Will users have to deal with this scenario
themselves (e.g. the send functions must return the number of bytes
sent)?

-bob

On May 7, 2006, at 2:56 PM, Rene Dudfield wrote:

> Hello,
>
> good work on the proposal.
>
> I think one important thing you missed out is testing the api on a
> couple of simple games.  Something turnbased. Something with lots of
> action. Something with lots of connections (eg 100 players).
>
> Are you going to address NAT traversal or other firewall hopping
> things?
>
> I think it is good that you kept highscores out of this system.  I
> think it can easily be implemented with urllib.
>
>
>
> On 5/8/06, Bryce Allen <pygame@xxxxxxxxxx> wrote:
>> Hello,
>>
>> I'm a student interested in working on Pygame for Google's Summer
>> of Code. I'm
>> working on a proposal to add an event based networking framework
>> to Pygame,
>> inspired by this Wiki entry:
>>
>> http://wiki.python.org/moin/SummerOfCode/PythonLibraries/
>> SimpleNetworkingForPygame
>>
>> The latest version of my proposal lives here:
>> http://www.mumstudents.org/~bda/soc/NetworkingForPygame.html
>>
>> I'm including my first draft below. Let me know what you think!
>>
>> Thanks,
>> Bryce Allen
>>
>>
>> * Proposal
>>
>> Create a networking framework for Pygame which integrates into the
>> event
>> queue, using the Python socket API. The framework will include both
>> peer-to-peer networking and game discovery via a game server or local
>> broadcast.
>>
>> * Acknowledgements
>>
>> http://wiki.python.org/moin/SummerOfCode/PythonLibraries/
>> SimpleNetworkingForPygame
>>
>> This proposal builds on ideas from the Summer of Code wiki. Thanks
>> to all the
>> contributers!
>>
>>
>> * Details
>>
>> Games have very different requirements in terms of networking -
>> typically each
>> game defines it's own high level protocol. However, there are
>> common needs
>> which may be shared among multiple games. Creating an inheritance
>> hiearchy of
>> protocols would promote reuse of protocol layers, and provide a
>> convenient
>> way to parsel off networking code. The events posted to the queue
>> would
>> depend on which protocol is initialized.
>>
>> I think the most useful mid-level protocol which would satisfy the
>> needs of
>> most games is a TCP based remote events protocol like dkeeney
>> suggested (see
>> the wiki link above). TCP is the easiest way to get reliable
>> delivery.
>> However, a UDP version could also be developed with a more
>> lightweight
>> connection management system, and it could be swapped in
>> seamlessly if it
>> emits the same events.
>>
>> TCP and UDP protocols would mainly be used by people implementing
>> their own
>> special purpose protocol. Creating a new protocol object
>> inheriting from TCP
>> or UDP and posting custom events would be encouraged, rather then
>> using the
>> TCP or UDP events directly. However, for simple games using the
>> TCP/UDP
>> events directly could be convenient.
>>
>> Game discovery could also be implemented through pluggable
>> classes. Specific
>> games could extend the basic classes with support for searching
>> for games
>> with specific options set, for example.
>>
>> Higher level protocols, like the remote events protocol, would
>> have it's own
>> (possibly pluggable) serialization. TCP and UDP would accept
>> strings only, as
>> suggested in the wiki. I think it is important to provide a simple
>> safe
>> serializer to discourage people from using pickle.
>>
>>
>> * Potential API
>>
>> # find a game to join
>> discovery = pygame.network.discovery.GameServer(gameGUID, server)
>> discovery = pygame.network.discovery.LocalBroadcast(gameGUID, server)
>>
>> # blocking version
>> gameDescriptors = discovery.list_games()
>>
>> # event queue version
>> discover.start_search()
>>
>> # initialize the network with a given protocol object
>> connection = gameDescriptor.get_connection() # from the game
>> descriptor
>> connection = pygame.network.TCPRemoteEvents(CLIENT, serverAddr)
>> pygame.network.init(connection)
>>
>> connection.start()
>>
>> # after we've gotten a connect event, we can send data
>> connection.send(event) # in the case of TCPRemoteEvents, we send
>> events
>>
>> # using it
>> pygame.network.pump_events()
>> pygame.network.discovery.pump_events()
>>
>> # some example events
>> for event in pygame.events.get()
>>     if e.type == NET:
>>         if e.what == NET_CONNECT:
>>             startGame()
>>     if e.type == NET_DISCOVERY:
>>         if e.what == NET_DISCOVERY_GAME_FOUND:
>>             # update display with available games
>>             print e.protocol
>>             print e.connection_arguments
>>             print e.options
>>     if e.type == KEYDOWN:
>>         if e.key == player1.keys.up:
>>             connection.send(Event(MyGlobals.PLAYER_MOVE_EVENT,
>> {"player" :
>> 1, "direction": Direction.UP} )
>>
>>
>>
>> * Protocol Inheritance
>>
>> # When inheriting from TCP or UDP, you can choose to pass or
>> consume the TCP
>> events and add new events
>>
>> # this would consume the standard TCP DATA_IN event and parse the
>> data into an
>> event object, then post the remote event to the local queue
>> pygame.network.init(TCPRemoteEvents(CLIENT, serverAddr))
>>