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

Re: [pygame] Easy networking module - feedback needed



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: ')

# version 1:
while True:
for e in pygame.event.get()
if e.type == NETWORK and isinstance(e.packet, echo):
user, msg = e.packet
print '%s: %s' % (user, msg)
host.send(echo('me', raw_input())
# version 2:
while True:
for e in pygame.event.get()
if e.type == NETWORK and e.packet_name == 'echo':
print '%s: %s' % (e.packet.user, e.packet.msg)
host.net_echo('me', raw_input())
# version 3:
class EchoClient(pygame_network.client.Receiver):
def net_echo(self, packet_id, packet):
print '%s: %s' % (packet.user, packet.msg)
def read_input(self):
self.host.net_echo('me', raw_input())
echo_client = EchoClient()
while True:
echo_client.read_input()
# version 4: (no need to register new packet)
class EchoClient(pygame_network.SyncObject):
sync_var = ('user', 'msg')
def __init__(self):
        super(EchoClient, self).__init__()
self.msg = 'test'
self.user = 'me'
def on_change(self):
print '%s: %s' % (self.user, self.msg)
echo_client = EchoClient()
while True:
echo_client.msg = raw_input()


Greetings

2012/6/20 René Dudfield <renesd@xxxxxxxxx>
Hi,

maybe it would help to sketch out how it would be used in a game?

A good way to do that, might be to show a very small example...  The classic minimal networking example is the echo server, and client.  The echo server just echos stuff back to the client.

A bit bigger one perhaps... In the chimp example, how would a remote player control the fist?


cheers,




On Wed, Jun 20, 2012 at 5:48 PM, Szymon Wróblewski <bluex0@xxxxxxxxx> wrote:
Hi,

I made the initial documentation describing the API and some internal classes. It can be found here:  http://pygame_network.readthedocs.org
I also have a few questions:
  • Whether the use of separate instances should be possible in manager classes (currently they share common state and all methods are classmethods)
  • Is it good idea to use threading or even multiprocessing for future classes that sends and receives data
Any suggestions and thoughts about project are welcome.

Thanks,
Szymon Wróblewski

2012/6/13 Szymon Wróblewski <bluex0@xxxxxxxxx>
Hi,

I'm writing network module for Pygame as my GSoC project and would be grateful for your suggestions and thoughts about it.

Here you can find more info:

Thanks,
Szymon Wróblewski