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

Re: [pygame] networking example



Whenever I think of networking I get depressed. The only thing I have
ever done so far with networking was junk like "Hello world, through a
socket!".

This is how I wish I could do networking with pyagme

#Setting up a connection
link = pygame.net.connection(address) #address is either a string with
an IP address or an URL.

#Checking for data
net_events = pygame.event.get(NET_DATA)
print net_events[0].source, "sent: ", net_events[0].data

#Checking for errors
net_events = pygame.event.get(NET_ERROR)
foreach event in net_events:
   print event.source, event.error_type #error_type can have values
like "connection refused", "connection lost", "ping timeout"...

#Sending data
link.send_data("B7 B6") #Moving a piece from B7 to B6

#Closing a connection
link.close()

But I guess we don't have anything that simple, do we?

-Thiago

On Sat, Apr 26, 2008 at 11:17 AM, Patrick Mullen <saluk64007@xxxxxxxxx> wrote:
> Well yes, LAN makes this easier, because you can pick a latency to
>  work with and it will be fairly consistent.  With a consistent
>  latency, you can send a message like: "bullet will be here by the time
>  you get this message" and it should be fairly accurate.  Unfortunately
>  there is currently no networking built into pygame, and yes I think
>  there were some people working on such a thing.  I think your best bet
>  at this point is to use something like twisted or raknet and build
>  your own scheme that fits your game.
>