Re: [pygame] Networking

2011-03-09 Thread Joseph Lewis
That does look like a great starting point, thanks Gregor.

--

Message Sent By: *Joseph Lewis III* joehm...@gmail.com
Public Key: 
[0xF8462E1593141C16]http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16

On Wed, Mar 9, 2011 at 4:29 PM, Gregor Lingl gregor.li...@aon.at wrote:



 Am 07.03.2011 15:03, schrieb Joseph Lewis:

 Twisted is a little large and written in Python, although I would like to
 prototype in Python, the goal would be to get the code to be an integral
 part of Pygame and fairly small.

 Twisted isn't a liitle large but *very* large. A small, useful and nicely
 designed Networking module is - imho  - PodSixNet (to be found an
 pygame.org), at least it might be a good starting point.

 Regards, Gregor


 I will look in to that, thanks.

 --

 Message Sent By: *Joseph Lewis* joehm...@gmail.com
 Public Key: 
 [0xF8462E1593141C16]http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16


 On Sun, Mar 6, 2011 at 11:08 PM, Alex Nordlund 
 deep.alexan...@gmail.comwrote:

 On Sun, Mar 6, 2011 at 7:32 AM, Joseph Lewis joehm...@gmail.com wrote:
  Does pygame have a networking module?  There doesn't seem to be anything
  about networking in the documentation or subversion.

  What's wrong with twisted?

 Also, you should look up Vertex, could simplify what you're proposing.


 ---
 //Alex





Re: [pygame] Networking

2011-03-07 Thread Joseph Lewis
Twisted is a little large and written in Python, although I would like to
prototype in Python, the goal would be to get the code to be an integral
part of Pygame and fairly small.

I will look in to that, thanks.

--

Message Sent By: *Joseph Lewis* joehm...@gmail.com
Public Key: 
[0xF8462E1593141C16]http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16


On Sun, Mar 6, 2011 at 11:08 PM, Alex Nordlund deep.alexan...@gmail.comwrote:

 On Sun, Mar 6, 2011 at 7:32 AM, Joseph Lewis joehm...@gmail.com wrote:
  Does pygame have a networking module?  There doesn't seem to be anything
  about networking in the documentation or subversion.

 What's wrong with twisted?

 Also, you should look up Vertex, could simplify what you're proposing.


 ---
 //Alex



Re: [pygame] Networking

2011-03-07 Thread Alex Nordlund
On Mon, Mar 7, 2011 at 2:03 PM, Joseph Lewis joehm...@gmail.com wrote:
 Twisted is a little large and written in Python, although I would like to
 prototype in Python, the goal would be to get the code to be an integral
 part of Pygame and fairly small.

But whenever networking is involved, it's usually best to use twisted.

---
//Alex


Re: [pygame] Networking

2011-03-06 Thread Ian Mallett
On Sun, Mar 6, 2011 at 12:32 AM, Joseph Lewis joehm...@gmail.com wrote:

 Hi,

 Does pygame have a networking module?  There doesn't seem to be anything
 about networking in the documentation or subversion.

 If there is no module I was thinking about building one through GSOC 2011,
 if pygame is participating of course, with some general features, such as:

- Chat (possibly with expletive filtering).
- A way to send objects transparently across the network.
- Possible multicast.
- A high level client server model to allow for quick setup of certain
kinds of games (i.e. turn based)
- Any other cool suggestions you have.

 Cheers,
 Joe

There are a number of networking modules as PyGame projects on pygame.org,
but no, PyGame does not have in-built networking support.


Re: [pygame] Networking

2011-03-06 Thread inigo.delg...@gmail.com
Well I've a petitions (or suggestions) I'm doing a online real-time game and
have to solve that problem...

I'll suggest you to do the thinks that are necessary from TCP to use over
UDP, that's:

A packet indexing method (to mantain the order of the packets in the
reciber, it can be done by inserting extra bits in the head of each packet)
A CRC to find errors.

To make online games, you prefer UDP vs TCP because UDP supports multicast
(well, the ISP's normally no, but the protocol yes) and because the
lost/corrupted packages are resended by stoping the queue (and that's no
aceptable for a game in real-time. In that sort of games you prefer to
recognize a damaged package and ignore it, TCP sends to emissor a ACK of
each package and THEN emissor sends the next one or resends the last one if
something went wrong... it sucks...). So the CRC will be a great idea.

The order: normally, I send to clients from server orders to draw in screen
(draw image A in screen coords x,y, image B in x1,y1...) but the order must
be known in the client (sending info in each package saying: now there is
the info of tho next screen to draw, the number X: draw a image A in screen
coords x,y, image B) so if the packet of the screen number X+1 arrives
to client before the X, the client will draw the X+1 and ignore the X.



2011/3/6 Joseph Lewis joehm...@gmail.com

 Hi,

 Does pygame have a networking module?  There doesn't seem to be anything
 about networking in the documentation or subversion.

 If there is no module I was thinking about building one through GSOC 2011,
 if pygame is participating of course, with some general features, such as:

- Chat (possibly with expletive filtering).
- A way to send objects transparently across the network.
- Possible multicast.
- A high level client server model to allow for quick setup of certain
kinds of games (i.e. turn based)
- Any other cool suggestions you have.

 Cheers,
 Joe

 --

 Message Sent By: *Joseph Lewis* joehm...@gmail.com
 Public Key: 
 [0xF8462E1593141C16]http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16




-- 
Nota: Tildes omitidas para evitar incompatibilidades.

:wq


Re: [pygame] Networking

2011-03-06 Thread Joseph Lewis
Great suggestions, thanks.  I'll definitely add those in to my proposal.
On Mar 6, 2011 3:09 PM, inigo.delg...@gmail.com inigo.delg...@gmail.com
wrote:
 Well I've a petitions (or suggestions) I'm doing a online real-time game
and
 have to solve that problem...

 I'll suggest you to do the thinks that are necessary from TCP to use over
 UDP, that's:

 A packet indexing method (to mantain the order of the packets in the
 reciber, it can be done by inserting extra bits in the head of each
packet)
 A CRC to find errors.

 To make online games, you prefer UDP vs TCP because UDP supports multicast
 (well, the ISP's normally no, but the protocol yes) and because the
 lost/corrupted packages are resended by stoping the queue (and that's no
 aceptable for a game in real-time. In that sort of games you prefer to
 recognize a damaged package and ignore it, TCP sends to emissor a ACK of
 each package and THEN emissor sends the next one or resends the last one
if
 something went wrong... it sucks...). So the CRC will be a great idea.

 The order: normally, I send to clients from server orders to draw in
screen
 (draw image A in screen coords x,y, image B in x1,y1...) but the order
must
 be known in the client (sending info in each package saying: now there is
 the info of tho next screen to draw, the number X: draw a image A in
screen
 coords x,y, image B) so if the packet of the screen number X+1 arrives
 to client before the X, the client will draw the X+1 and ignore the X.



 2011/3/6 Joseph Lewis joehm...@gmail.com

 Hi,

 Does pygame have a networking module? There doesn't seem to be anything
 about networking in the documentation or subversion.

 If there is no module I was thinking about building one through GSOC
2011,
 if pygame is participating of course, with some general features, such
as:

 - Chat (possibly with expletive filtering).
 - A way to send objects transparently across the network.
 - Possible multicast.
 - A high level client server model to allow for quick setup of certain
 kinds of games (i.e. turn based)
 - Any other cool suggestions you have.

 Cheers,
 Joe

 --

 Message Sent By: *Joseph Lewis* joehm...@gmail.com
 Public Key: [0xF8462E1593141C16]
http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16




 --
 Nota: Tildes omitidas para evitar incompatibilidades.

 :wq


Re: [pygame] Networking

2011-03-06 Thread Alex Nordlund
On Sun, Mar 6, 2011 at 7:32 AM, Joseph Lewis joehm...@gmail.com wrote:
 Does pygame have a networking module?  There doesn't seem to be anything
 about networking in the documentation or subversion.

What's wrong with twisted?

Also, you should look up Vertex, could simplify what you're proposing.


---
//Alex


[pygame] Networking

2011-03-05 Thread Joseph Lewis
Hi,

Does pygame have a networking module?  There doesn't seem to be anything
about networking in the documentation or subversion.

If there is no module I was thinking about building one through GSOC 2011,
if pygame is participating of course, with some general features, such as:

   - Chat (possibly with expletive filtering).
   - A way to send objects transparently across the network.
   - Possible multicast.
   - A high level client server model to allow for quick setup of certain
   kinds of games (i.e. turn based)
   - Any other cool suggestions you have.

Cheers,
Joe

--

Message Sent By: *Joseph Lewis* joehm...@gmail.com
Public Key: 
[0xF8462E1593141C16]http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xF8462E1593141C16


Re: [pygame] Networking library

2009-04-14 Thread Chris McCormick
On Sat, Apr 11, 2009 at 10:17:35AM -0700, Patrick Mullen wrote:
 On Sat, Apr 11, 2009 at 2:55 AM, Chris McCormick ch...@mccormick.cx wrote:
  Hi,
 
  On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:
  Python2.6 comes with json.  Other than that, it is a small thing to 
  include.
 
  The library seems to be built around json, so removing it as a
  dependency doesn't make much sense.
 
  Actually I don't think it would be a huge job to change the serialisation
  method to something else, optionally. I'll have a look it and see. My only
  concern is about security - I chose JSON serialisation over something like
  pickling because there's no way a client can inject malicious code using 
  JSON.
  I wonder if there's some other safe, built-in, pythonic way of serialising 
  data
  structures that I don't know about?
 
 True. You could probably make the serialization abstract and allow
 other methods, by plugging in a different Serializer class of some
 sort.  Other than json, yaml, xml, etc I don't know any other good
 serialization for python, and everything I can think of is a
 dependency. Maybe for easy testing it could work with repr/eval, but
 prefers json if it is there.  (Repr/eval can serialize the same
 dictionaries that json can, and I think it's a bit faster too, its
 just a bit more dangerous)

After talking to a friend who suggested a few different serialisation methods,
like gherkin, and rencode, I tried implementing a serialisation wrapper layer
that lets you choose how to serialise, but gherkin and rencode both didn't
produce the exact structures that went in, coming out, so I'm going to have to
work a bit harder. I will definately steer clear of repr/eval, but I might try
out the other snippet that was posted here. Hopefully I'll come up with
something faster and lighter than JSON, with the option to use JSON. Will post
back here if and when I get it working.

Thanks for your interest.

Best,

Chris.

---
http://mccormick.cx


Re: [pygame] Networking library

2009-04-14 Thread David
Chris:

Could you share your test code, that you used to evaluate gherkin and rencode?

David

On Tue, Apr 14, 2009 at 3:25 AM, Chris McCormick ch...@mccormick.cx wrote:
 After talking to a friend who suggested a few different serialisation methods,
 like gherkin, and rencode, I tried implementing a serialisation wrapper layer
 that lets you choose how to serialise, but gherkin and rencode both didn't
 produce the exact structures that went in, coming out, so I'm going to have to
 work a bit harder. I will definately steer clear of repr/eval, but I might try
 out the other snippet that was posted here. Hopefully I'll come up with
 something faster and lighter than JSON, with the option to use JSON. Will post
 back here if and when I get it working.

-- 
dkee...@travelbyroad.net
Pitcher's Duel - pitchersduel.python-hosting.com


Re: [pygame] Networking library

2009-04-14 Thread Chris McCormick
Hi David,

I've put a bzr branch of the serialisation stuff here:

bzr co http://mccormick.cx/dev/PodSixNet.serialise/

Let me know if you need me to tar it up or whatever instead. I've had a closer
look and the issue is slightly different for each serialisation method. All
work in my unit tests, but when I run the whiteboard example everything except
json breaks. You can reproduce this by:

* Changing Channel.py to:
'from serialise.rencode import *' or
'from serialise.gherkin import *' or
'from serialise.json import *'
(I'll make that easy to configure at runtime in future)
* Run the unit tests:
python EndPoint.py
python Server.py
* Run the examples:
python examples/WhiteboardServer.py 
python examples/WhiteboardClient.py 
python examples/WhiteboardClient.py

Rencode fails on the whiteboard example because when it deserialises lists,
they are tuples by default which means you can't use them directly in your code
without turning them back into lists, unless you don't want to modify them. I
don't like that because it puts the onus on the library user to do that
tuple-to-list jiggery when it should Just Work. On the other hand, gherkin
fails with this cryptic message, only when connecting with a second client:
ValueError(Type prefix not supported. ('\\x96'),). So I am sending some
data down the socket which gherkin doesn't like. I am CC'ing the gherkin author
to see if he can help me decypher what's going on there. If it's a simple fix I
am probably going to go with using gherkin by default with the option of
simplejson in  py2.6, and the built-in json for = py2.6

Patches welcome!

Best,

Chris.

On Tue, Apr 14, 2009 at 08:24:40AM -0600, David wrote:
 Chris:
 
 Could you share your test code, that you used to evaluate gherkin and rencode?
 
 David
 
 On Tue, Apr 14, 2009 at 3:25 AM, Chris McCormick ch...@mccormick.cx wrote:
  After talking to a friend who suggested a few different serialisation 
  methods,
  like gherkin, and rencode, I tried implementing a serialisation wrapper 
  layer
  that lets you choose how to serialise, but gherkin and rencode both didn't
  produce the exact structures that went in, coming out, so I'm going to have 
  to
  work a bit harder. I will definately steer clear of repr/eval, but I might 
  try
  out the other snippet that was posted here. Hopefully I'll come up with
  something faster and lighter than JSON, with the option to use JSON. Will 
  post
  back here if and when I get it working.
 
 -- 
 dkee...@travelbyroad.net
 Pitcher's Duel - pitchersduel.python-hosting.com
---
http://mccormick.cx


Re: [pygame] Networking library

2009-04-11 Thread Chris McCormick
Hi,

On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:
 Python2.6 comes with json.  Other than that, it is a small thing to include.
 
 The library seems to be built around json, so removing it as a
 dependency doesn't make much sense.

Actually I don't think it would be a huge job to change the serialisation
method to something else, optionally. I'll have a look it and see. My only
concern is about security - I chose JSON serialisation over something like
pickling because there's no way a client can inject malicious code using JSON.
I wonder if there's some other safe, built-in, pythonic way of serialising data
structures that I don't know about?

 The whiteboard example is very impressive!  It looks a lot easier to
 start working with than twisted.

Thanks! My intention was for it to be extremely simple, and lightweight, which
Twisted isn't (/me dons his flame retardant suit). Part of being lightweight
and simple is probably removing dependencies on unneccesary third party
libraries, so I think I will have a crack at removing the simplejson
requirement, and also making the built-in JSON of 2.6 useable.

Best,

Chris.

---
http://mccormick.cx


Re: [pygame] Networking library

2009-04-11 Thread Nicholas Dudfield

Meh,  thunderbird always ruins formatting ... safe_eval.py attached
import compiler

class Unsafe_Source_Error(Exception):
def __init__(self,error,descr = None,node = None):
self.error = error
self.descr = descr
self.node = node
self.lineno = getattr(node,lineno,None)

def __repr__(self):
return Line %d.  %s: %s % (self.lineno, self.error, self.descr)
__str__ = __repr__
   
class SafeEval(object):
def visit(self, node,**kw):
cls = node.__class__
meth = getattr(self,'visit'+cls.__name__,self.default)
return meth(node, **kw)

def default(self, node, **kw):
for child in node.getChildNodes():
return self.visit(child, **kw)

visitExpression = default

def visitConst(self, node, **kw):
return node.value

def visitDict(self,node,**kw):
return dict([(self.visit(k),self.visit(v)) for k,v in node.items])

def visitUnarySub(self, node, **kw):
return -self.visit(node.getChildNodes()[0])

def visitTuple(self,node, **kw):
return tuple(self.visit(i) for i in node.nodes)

def visitList(self,node, **kw):
return [self.visit(i) for i in node.nodes]

class SafeEvalWithErrors(SafeEval):
def default(self, node, **kw):
raise Unsafe_Source_Error(Unsupported source construct,
node.__class__,node)

def visitName(self,node, **kw):
if node.name == 'None':
return None

if node.name == 'True':
return True

if node.name == 'False':
return False

raise Unsafe_Source_Error(Strings must be quoted, 
 node.name, node)

# Add more specific errors if desired

def safe_eval(source, fail_on_error = True):
walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
try:
ast = compiler.parse(source,eval)
except SyntaxError, err:
raise
try:
return walker.visit(ast)
except Unsafe_Source_Error, err:
raise

[pygame] Networking library

2009-04-10 Thread Chris McCormick
Hi All,

I posted this as a project page on the pygame website, but I'm not getting much
traction with my library, so I thought I'd post it here to see if anyone is
interested.

Basically it's a [hopefully] super-easy-to-use networking library that works
well with Pygame too. Included is a simple networked whiteboard demo written in
pure Pygame.

http://mccormick.cx/projects/PodSixNet/

Have fun, and please let me know what you thik, or if you find bugs, or need 
help.

Best,

Chris.

---
http://mccormick.cx


Re: [pygame] Networking library

2009-04-10 Thread Ian Mallett
I'm sure it might be a pain, but removing the dependency on simplejson would
be really great.  Either, that, or include it in the distr.
-Ian


Re: [pygame] Networking library

2009-04-10 Thread Michael Fiano
I agree, preferably the former :)

On Fri, Apr 10, 2009 at 6:07 PM, Ian Mallett geometr...@gmail.com wrote:

 I'm sure it might be a pain, but removing the dependency on simplejson
 would be really great.  Either, that, or include it in the distr.
 -Ian



Re: [pygame] Networking library

2009-04-10 Thread Patrick Mullen
Python2.6 comes with json.  Other than that, it is a small thing to include.

The library seems to be built around json, so removing it as a
dependency doesn't make much sense.

I took a look at this library when you announced it and thought it
looks good, but I haven't had a chance to really try it out.

The whiteboard example is very impressive!  It looks a lot easier to
start working with than twisted.


Re: [pygame] Re:[pygame] networking example

2008-05-08 Thread Jake b
Thanks for the info.

I've been going through the Twisted tutorials. I tried out raknet, but
I only found one tutorial.

Here's psuedo code I wrote trying to accomplish the Asteroids demo
above. Am I heading in the right direction?

Should I be using LineReceiver() and just send text messages like
that? Will parsing the message strings be too slow? Or should I be
using actual python objects in the messages? I'm not sure how I can
handle the data.

# Should I be using text messages, or be using python lists?
# Snippet from tutorial: finger19a.py
def getUser(self, user):
return defer.succeed(self.users.get(user, No such user))
def getUsers(self):
return defer.succeed(self.users.keys())
def setUser(self, user, status):
self.users[user] = status

# Here's my psuedo code test:
import twisted stuff # psuedo code import

# == game_client.py ==
class GameClient( basic.LineReceiver ): # or wrong class for the client?
def __init__(self):
self.asteroids = [] # list of: Asteroid(Actor):
self.bullets = [] # list of: Bullet(Actor):
self.ships = [] # list of: Ship(Actor):
self.state = round start

def keyboard_input(self):
if keyPressed['fire'] and cooldownDone():
msg = fire, bullet, %d, %d % ( self.loc.x, self.loc.y )
self.factory.server.message( msg )

def loop(self):
main loop
if self.state == round start:
self.factory.server.message( ready )

elif self.state == round:

self.keyboard_input()
physics_update()
graphics_draw()

# update my location to server
if time_elapsed( 150 ms ): # but only ever Xms elapsed
id, x, y = self.ship.ID, self.ship.loc.x, self.ship.loc.y
self.factory.server.message(player, %d, %d, %d % (id, x, y ) )

# else: always:
sleep() # or not?

def lineReceived(self, line):
string received command from clients
example: 'fire, bullet, x, y' 
cmds = splitIntoCmds(line)
if cmds[0] == fire:
self.spawn( cmds[1:] ) # arg is the rest of the command
if cmds[0] == player:
id, x, y = cmds[1], cmds[2], cmds[3]
self.ships[id].loc = (x, y )

# == game_server.py ==
class GameServer(basic.LineReceiver): # Maybe wrong type to descend from
def __init__(self):
self.asteroids = [] # list of: Asteroid(Actor):
self.bullets = [] # list of: Bullet(Actor):
self.ships = [] # list of: Ship(Actor):
self.state = round start

def randomAsteroids(self):
init randomized asteroids
self.spawn( asteroid, %d, %d % ( rand(), rand() )

def loop(self):
main loop
if self.state = round start:
self.randomAsteroids()
self.state = round # could wait till I get a 'ready'
from all players
elif self.state = round:
self.update() # update physics
# also update players movements to each other
for c in self.factory.clients:
c.message( player, ID, loc )

sleep() # or not ?

def spawn(self, cmds):
spawn something: unit, x, y
and notify clilents
unit, x, y = cmds[0], cmds[1], cmds[2]
if unit == bullet:
self.bullets.append( Bullet( x, y ) )
elif unit == asteroid:
self.asteroids.append( Asteroid( x, y ) )

# notify clients of new Actor()'s
msg = spawn: %s, %d, %d % ( unit, x, y )
for c in self.factory.clients:
c.message(msg)

def lineReceived(self, line):
string received command from clients
example: 'fire, bullet, x, y' or 'player, ID, x, y' 
cmds = splitIntoCmds(line)
if cmds[0] == fire:
self.spawn( cmds[1:] ) # arg is the rest of the command
if cmds[0] == player:
id, x, y = cmds[1], cmds[2], cmds[3]
self.ships[id].loc = (x, y )

thanks,
-- 
Jake


Re: [pygame] Re:[pygame] networking example

2008-04-30 Thread Brian Davis
Here are the actual scripts:

***BEGIN asynchat_serv.py ***
#!/usr/bin/python
### This is the game server ###
import asynchat
import asyncore
import socket

class GameServer(asyncore.dispatcher):
 The GameServer (mastermind controlling all)

def __init__(self, port):
asyncore.dispatcher.__init__(self)
# create connection
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
here = (, port)
self.bind(here)
self.listen(5)

def handle_accept(self):
# accept a connection and create a chat object to handle it
print Accepting connection
GameChat(self, self.accept())

class GameChat(asynchat.async_chat):
 This is the GameChat class. Collects messages and updates other clients.


def __init__(self, server, (conn, addr)):
asynchat.async_chat.__init__(self, conn)
self.set_terminator('\n')
self.server = server
self.buffer = ''

def collect_incoming_data(self, data):
self.buffer = self.buffer + data

def found_terminator(self):
# handle end of message
data = self.buffer
# clear the buffer
self.buffer = ''
print Server Received: %s % (data)

cmd = data[:3]
message = data[4:]
# check for any special commands
if cmd == HEL:
print %s said Hello % message
self.push(Hello %s\n % message)

def handle_close(self):
print 'Closing'
self.close()

if __name__ == __main__:
# test the server here
gs = GameServer(5000)
#asyncore.loop()# I think asyncore has a longer timeout
because it takes a long time to kill with ctrl-c
while (1):
asyncore.poll(timeout=.01)

*** END asynchat_serv.py ***

*** BEGIN asynchat_client.py ***
# the client side

import asynchat
import asyncore
import socket


class GameClient(asynchat.async_chat):
 GameClient class. Connects to the server and sends messages.

def __init__(self, host, port):
asynchat.async_chat.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.buffer = 
self.set_terminator(\n)
self.address = (host, port) # address of the server to contact
self.connect(self.address)
self.push(HEL BOB\n\n)

def handle_connect(self):
print Connection Complete

def collect_incoming_data(self, data):
self.buffer = self.buffer + data

def found_terminator(self):
data = self.buffer
self.buffer = 
print Client received: %s % (data)

def handle_close(self):
self.close()


if __name__ == __main__:
gc = GameClient(localhost, 5000)
while (1):
asyncore.poll(timeout=.01)



*** END asynchat_client.py ***

On Tue, Apr 29, 2008 at 6:57 PM, Jake b [EMAIL PROTECTED] wrote:
 Brian: I am getting a 404 not found on both of your links.

  --
  Jake




-- 
Brian Davis
[EMAIL PROTECTED]
[EMAIL PROTECTED]


Re: [pygame] Re:[pygame] networking example

2008-04-29 Thread Jake b
Brian: I am getting a 404 not found on both of your links.

-- 
Jake


Re: [pygame] Re:[pygame] networking example

2008-04-28 Thread Brian Davis
I found the twisted docs a bit hard to follow and wound up building
something on asynchat.

http://docs.python.org/lib/module-asynchat.html

Here is a simple example:
Server: http://rafb.net/p/kU58yg32.html
Client: http://rafb.net/p/sI2FRw42.html

   Starting with something like that it's just a matter of defining
your state machine and the messages you are going to send. Have your
client generate some pygame events, stick the client's asyncore.poll
in your pygame loop and away you go. I'm sure it's not very robust or
secure but it was a good way for me learn about network programming.

On Sun, Apr 27, 2008 at 9:33 AM, Patrick Mullen [EMAIL PROTECTED] wrote:

 Found you an exe and an egg:
 http://www.zope.org/Members/saffe/zope_interface/folder_contents

 Really annoying when binaries stop being updated.

 You could also just use sockets of course, they aren't that difficult
 really.

 Also, raknet uses udp, but it has built-in workarounds for all of udp's
 problerms.  It can send both reliable packets, and break through NAT's,
 which are the two most difficult issues with using UDP.  Messaging is
 actually easier with UDP because you send datagrams (messages) instead of a
 constant stream of bits.

 Good luck!



Re: [pygame] Re:[pygame] networking example

2008-04-27 Thread Patrick Mullen
Found you an exe and an egg:
http://www.zope.org/Members/saffe/zope_interface/folder_contents

Really annoying when binaries stop being updated.

You could also just use sockets of course, they aren't that difficult
really.

Also, raknet uses udp, but it has built-in workarounds for all of udp's
problerms.  It can send both reliable packets, and break through NAT's,
which are the two most difficult issues with using UDP.  Messaging is
actually easier with UDP because you send datagrams (messages) instead of a
constant stream of bits.

Good luck!


Re: [pygame] networking example

2008-04-26 Thread Patrick Mullen
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.


Re: [pygame] networking example

2008-04-26 Thread Thiago Chaves
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 [EMAIL PROTECTED] 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.



Re: [pygame] Networking?

2007-11-21 Thread Michael Sparks
On Wednesday 21 November 2007 06:51:38 Jason Ward wrote:
 Thanks for the options guys. I'll look into them when I find the time. But I
 don't mind low-level stuff if that's what sockets library requires, just as
 long as it can work.

Sure of course it'll work. The code is pretty much the same as you'd find for 
C based code. We're just trying to save you hassle :-)  If you enjoy it 
though, go for it :-)

 I looked into twisted but it's documentation is rather difficult and I hate 
 libraries that want the main loop, I prefer the control.

FWIW, Kamaelia differs from twisted in that, aside from network systems not
being its sole focus, in that it recognises that systems like games, network
servers and most interactive systems tend to need multiple threads of control
and focusses on making that simpler  clearer to work with as well as
composable. (networking was the first use case, but was never intended to
be the sole focus)

As a result _you_ create a component for each logical thread of control.
Performance wise this can be pretty similar to hardcoding it yourself (the
difference is around 5% last time I measured), but the benefit you get is
more explicit control over the main loop for each thing, with a built in way
of allowing communication between the main loops.

You can use threads to do this:

class ConsoleReader(Axon.ThreadedComponent.threadedcomponent):
   def main(self):
      while 1:
          X = raw_input( )
          self.send(X, outbox)

class ConsoleEchoer(Axon.ThreadedComponent.threadedcomponent):
   def main(self):
      while 1:
          while self.dataReady(inbox):
               X = self.recv(inbox)
               print X

And then join the dots between them:

Pipeline(
    ConsoleReader(),
    ConsoleEchoer(),
).run()

Or make the components run in the same thread as all the others by changing to 
a generator:

class ConsoleEchoer(Axon.Component.component):
   def main(self):
      while 1:
          while self.dataReady(inbox):
               X = self.recv(inbox)
               print X
          yield 1

But either way, it allows you to have as many main loops *you* want in a piece 
of code that make sense in a relatively natural  scalable way. (Generator 
components are pretty much equivalent to state machines intermediate buffers, 
just somewhat more direct)

You don't have to use Kamaelia's networking or pygame components for it to
be useful, but if you're thinking I need to do more than one thing at once,
maybe I should use threads, take a look. Kamaelia can't magically solve your 
problems of course, so this just a suggestion.

Unlike some systems, the core of Kamaelia isn't really the components
(which are IMO the useful bit), but really just a core concurrency framework -
Axon - which builds the support that enables the above. We've got a simple
tutorial that's targetted to explain the approach here where you build your
own core:
   http://kamaelia.sourceforge.net/MiniAxon/

And you can happily build systems using such a beast. Indeed, the first pygame 
components we had came from someone's mini-axon system.

I love pygame, but these days I'd never use it by itself :-)
(Even if Kamaelia isn't really quite the same model as pygame :-)

If you do go down the route of coding your own networking though, I'm sure 
others would find your ideas/approach interesting :-)

The networked pong example was a 20-30 minute hack BTW from start
to finish. I'm now MASSIVELY off topic though, so I'll stop there :-)


Michael.


Re: [pygame] Networking?

2007-11-21 Thread David
On 11/20/07, Richard Jones [EMAIL PROTECTED] wrote:

  2) Use the Twisted reactor *as* your main loop, and implement all game
  logic as call-backs from there. This is the approach that the Twisted
  people will recommend.

 This is also useless for highly interactive games.


I consider my game highly interactive, though the network traffic intensity
is not very high.  Can you elaborate
on why the Twisted reactor is useless?


  3) Run the Twisted reactor in its own thread

 This is probably the only reasonable approach for games.


My only experience with threads was in writing an image slideshow program.
The graphic blends
and transitions were very jerky with threads.  Changing to a
generator-coroutine approach worked more
smoothly.   I do not recall any capability in the thread modules for
adjusting 'niceness' or state-change frequency.



  5)  Run the Twisted reactor in its own process, and use pipes or sockets
 to
  pass data between
  it and the main loop/process.  This has the merit of using the OS's CPU
  allocation management
  rather than that of Python's thread manager.

 Quite difficult to manage on Windows.


Windows is my development platform.  I'll let you know how it works out. ;)

Richard

Thanks for the input.


-- 
[EMAIL PROTECTED]
Pitcher's Duel - pitchersduel.python-hosting.com


Re: [pygame] Networking?

2007-11-21 Thread AlgoMantra
hey, please forgive me for any stupid observations.it's just
that I've been avoiding testing Twisted because people seem
to be of the opinion that it takes over the main loop. And they
like having control over that.

Can the main reactor be manipulated in such a way that it is
not the main loop?


RE: [pygame] Networking?

2007-11-21 Thread Chris Ashurst
I hope you mean that the sockets library is not the place to start, simply
because it's not immediately easy (unlike Twisted) to get right into? I
believe every programmer who wants to use a higher-level library should at
least have a stab at the low-level stuff, just to give a better idea of
what's going on behind the automagical scenese of things like Twisted
 
Rather than haul in Twisted, a little research on the Python select module
could be the very thing people are looking for - all without having any
extra dependencies/includes other than the core Python library and Pygame.
 
http://www.amk.ca/python/howto/sockets/
http://www.amk.ca/python/howto/sockets/ -  - the Non-blocking Sockets
section is particularly enlightening
 
If potential socketeers out there are worried about things like byte-order
and so on, remember that the IRC protocol is 100% ASCII-based, and whilst it
may have its problems here and there, for the most part it's one of the
oldest, reliable protocols available (and great to learn from).
 
---
 
The python sockets library is probably *not* the place to start.  It is very
primitive,
and most references you will read will recommend using a  higher level
library such as
asyncore or (higher yet) asynchat.  Unfortunately, these higher level
libraries share the 
same weakness as Twisted, in that that they expect to own the main loop.
 
---
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of David
Sent: Tuesday, November 20, 2007 09:44
To: pygame-users@seul.org
Subject: Re: [pygame] Networking?


 
The python sockets library is probably *not* the place to start.  It is very
primitive,
and most references you will read will recommend using a  higher level
library such as
asyncore or (higher yet) asynchat.  Unfortunately, these higher level
libraries share the 
same weakness as Twisted, in that that they expect to own the main loop.
 
I have identified five general approaches to integrating networking with a 
pygame application.  I have not fully implemented a game with any of them,
.. but soon.
 
1)  Use Twisted with reactor.iterate .  This is the easiest approach, and
the one that 
Mr Wittber's library uses.  Use of reactor.iterate is unfortunately
deprecated by the Twisted 
developers, and will, presumably, be removed from Twisted in some future
release.
 
2) Use the Twisted reactor *as* your main loop, and implement all game logic
as call-backs from 
there.  This is the approach that the Twisted people will recommend.   This
approach
is quite burdensome, in that structuring your game into a series of
callbacks can be difficult.  Using
generators as coroutines provides some relief, in that you can pass the
generators 'next' method 
as a callback to Twisted, and maintain game state within the generator.
Using subroutines or 
nested generators involve their own awkwardnesses.
 
3) Run the Twisted reactor in its own thread, and use ThreadedSelectReactor
to move 
data to the pygame event queue.  Bob Ippolito has blogged on how to use this
with Pygame (GIYF).
Unfortunately, ThreadedSelectReactor is unmaintained and deprecated.
 
4)  Run the Twisted reactor in its own thread, and use thread-safe queues to
move data 
to and from the main thread.  Alternatively, if you wish to use the
perspective-broker 
features or use Twisted code beyond mere message passing, there are tools in
Twisted for
safely invoking methods in other threads.  Hmm. maybe these were deprecated
with the TSR?
 
5)  Run the Twisted reactor in its own process, and use pipes or sockets to
pass data between
it and the main loop/process.  This has the merit of using the OS's CPU
allocation management 
rather than that of Python's thread manager.
 
Most of these approaches could use asyncore/asynchat as an alternative to
Twisted.
 
My own efforts lately have been along approaches 2 and 5.   My engine
'Spyre' will run under 
Twisted's reactor now, but the getting the whole multi-engine game logic
sequence working in 
the 'inside-out' callback style is an imposing prospect.  
 
Philip Hassey has recently released a networked pygame-based game.  Has he
mentioned what 
networking approach he used?
 
David
 
On 11/19/07, Jason Ward  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
wrote: 

I want to make my game playable over the network and if possible the
internet.
For the network it must support more than 2 computers and be realtime
Would the sockets library in python solve all my needs?




-- 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
Pitcher's Duel - pitchersduel.python-hosting.com
http://pitchersduel.python-hosting.com  





CONFIDENTIAL NOTICE: This email including any attachments, contains 
confidential information belonging to the sender. It may also be 
privileged or otherwise protected by work product immunity or other 
legal rules. This information is intended only for the use of the 
individual or entity named above.  If you are not the intended 
recipient, you are hereby notified

Re: [pygame] Networking?

2007-11-21 Thread David
On 11/21/07, Chris Ashurst [EMAIL PROTECTED] wrote:
 I hope you mean that the sockets library is not the place to start, simply
 because it's not immediately easy (unlike Twisted) to get right into? I
 believe every programmer who wants to use a higher-level library should at
 least have a stab at the low-level stuff, just to give a better idea of
 what's going on behind the automagical scenese of things like Twisted

What I meant is that to accomplish something usefull using the sockets
library, you have to build higher level systems, and you end up
reinventing asyncore or Twisted.   Reinventing sucks.

 Rather than haul in Twisted, a little research on the Python select module
 could be the very thing people are looking for - all without having any
 extra dependencies/includes other than the core Python library and Pygame.

To each their own, but I consider additional pure-python dependencies
to be a non-issue.  If including an extra 100K of library code saves
me a couple hours of work, I am all for it.   Non-pure-python
dependencies are an issue, because they may not build on the users
machine.

 http://www.amk.ca/python/howto/sockets/
 http://www.amk.ca/python/howto/sockets/ -  - the Non-blocking Sockets
 section is particularly enlightening

This is actually the document I would refer people to, to scare them
away from socket programming. ;)

Quotes:

 # This is a 10,000 foot overview of sockets. It's not really a
tutorial - you'll still have
 # work to do in getting things operational. It doesn't cover the fine
points (and there
 # are a lot of them), but I hope ...

 # There's no question that the fastest sockets code uses non-blocking sockets
 #  and select to multiplex them. ... The trouble is that an  app
written this way
 #  can't do much of anything else - it needs to be ready to shuffle
bytes around at
 # all times.

That document was written in the mid 1990's, and the state of
networking in Python has advanced since then.

As a matter of context, this is a Pygame mailing list, and presumably
list-members are interested in getting their game complete and robust.
 A networking library is just a tool to getting the cool game-state
from this server to that client (and client events back to the
server), not a contributer to game-state coolness.  No disrespect to
socket-twiddlers, and I get the impression the original poster may be
one himself, but many on the list are interested in easy toolkits to
just get 'er done.

David

-- 
[EMAIL PROTECTED]
Pitcher's Duel - pitchersduel.python-hosting.com


Re: [pygame] Networking?

2007-11-21 Thread Richard Jones
On Thu, 22 Nov 2007, David wrote:
 On 11/20/07, Richard Jones [EMAIL PROTECTED] wrote:
   2) Use the Twisted reactor *as* your main loop, and implement all game
   logic as call-backs from there. This is the approach that the Twisted
   people will recommend.
 
  This is also useless for highly interactive games.

 I consider my game highly interactive, though the network traffic intensity
 is not very high.  Can you elaborate
 on why the Twisted reactor is useless?

The minimum time you can pass to iterate() is quite high -- 0.01 seconds IIRC. 
This means a significant amount of processing time is lost.

A possible solution is to only run the reactor.iterate() once every few 
frames.


   3) Run the Twisted reactor in its own thread
 
  This is probably the only reasonable approach for games.

 My only experience with threads was in writing an image slideshow program.
 The graphic blends
 and transitions were very jerky with threads.  Changing to a
 generator-coroutine approach worked more
 smoothly.   I do not recall any capability in the thread modules for
 adjusting 'niceness' or state-change frequency.

True - this is a problem I ran into. The only solution I could find was to 
have the thread periodically artificially block using a semaphore.


 Richard


Re: [pygame] Networking?

2007-11-20 Thread David
The python sockets library is probably *not* the place to start.  It is very
primitive,
and most references you will read will recommend using a  higher level
library such as
asyncore or (higher yet) asynchat.  Unfortunately, these higher level
libraries share the
same weakness as Twisted, in that that they expect to own the main loop.

I have identified five general approaches to integrating networking with a
pygame application.  I have not fully implemented a game with any of them,
.. but soon.

1)  Use Twisted with reactor.iterate .  This is the easiest approach, and
the one that
Mr Wittber's library uses.  Use of reactor.iterate is unfortunately
deprecated by the Twisted
developers, and will, presumably, be removed from Twisted in some future
release.

2) Use the Twisted reactor *as* your main loop, and implement all game logic
as call-backs from
there.  This is the approach that the Twisted people will recommend.   This
approach
is quite burdensome, in that structuring your game into a series of
callbacks can be difficult.  Using
generators as coroutines provides some relief, in that you can pass the
generators 'next' method
as a callback to Twisted, and maintain game state within the generator.
Using subroutines or
nested generators involve their own awkwardnesses.

 3) Run the Twisted reactor in its own thread, and use ThreadedSelectReactor
to move
data to the pygame event queue.  Bob Ippolito has blogged on how to use this
with Pygame (GIYF).
Unfortunately, ThreadedSelectReactor is unmaintained and deprecated.

4)  Run the Twisted reactor in its own thread, and use thread-safe queues to
move data
to and from the main thread.  Alternatively, if you wish to use the
perspective-broker
features or use Twisted code beyond mere message passing, there are tools in
Twisted for
safely invoking methods in other threads.  Hmm. maybe these were deprecated
with the TSR?

5)  Run the Twisted reactor in its own process, and use pipes or sockets to
pass data between
it and the main loop/process.  This has the merit of using the OS's CPU
allocation management
rather than that of Python's thread manager.

Most of these approaches could use asyncore/asynchat as an alternative to
Twisted.

My own efforts lately have been along approaches 2 and 5.   My engine
'Spyre' will run under
Twisted's reactor now, but the getting the whole multi-engine game logic
sequence working in
the 'inside-out' callback style is an imposing prospect.

Philip Hassey has recently released a networked pygame-based game.  Has he
mentioned what
networking approach he used?

David

On 11/19/07, Jason Ward [EMAIL PROTECTED] wrote:

 I want to make my game playable over the network and if possible the
 internet.
 For the network it must support more than 2 computers and be realtime
 Would the sockets library in python solve all my needs?




-- 
[EMAIL PROTECTED]
Pitcher's Duel - pitchersduel.python-hosting.com


Re: [pygame] Networking?

2007-11-20 Thread Casey Duncan

On Nov 19, 2007, at 11:08 AM, Jason Ward wrote:

I want to make my game playable over the network and if possible  
the internet.

For the network it must support more than 2 computers and be realtime
Would the sockets library in python solve all my needs?


The appropriate tool totally depends on the game. What works good for  
a turn based game isn't gonna fly for a first person shooter, for  
instance.


I would use sockets in the following circumstances:

- You need low-level control and are already familiar with socket  
programming and serializing/de-serializing across the wire. Note that  
you will also need to know how to use async i/o or threads as well.
- You really want to want to learn all of the above and have a lot of  
time and enthusiasm.


First I would see if there is another similar game out there that  
already supports networking. How did they do it?


-Casey


Re: [pygame] Networking?

2007-11-20 Thread Michael Schmidt
hi
this application offers in the next version a network layer
http://sourceforge.net/forum/forum.php?thread_id=1870200forum_id=618174
please have a look, if it is ready in the SVN or next release
thanks Mike


2007/11/19, Jason Ward [EMAIL PROTECTED]:

 I want to make my game playable over the network and if possible the
 internet.
 For the network it must support more than 2 computers and be realtime
 Would the sockets library in python solve all my needs?



Re: [pygame] Networking?

2007-11-20 Thread Richard Jones
On Wed, 21 Nov 2007, David wrote:
 1)  Use Twisted with reactor.iterate

I found that this approach has quite a high impact (ie. takes a considerable 
amount of time to run, even when there's no network events).


 2) Use the Twisted reactor *as* your main loop, and implement all game
 logic as call-backs from there. This is the approach that the Twisted
 people will recommend.

This is also useless for highly interactive games.


  3) Run the Twisted reactor in its own thread

This is probably the only reasonable approach for games.


 5)  Run the Twisted reactor in its own process, and use pipes or sockets to
 pass data between
 it and the main loop/process.  This has the merit of using the OS's CPU
 allocation management
 rather than that of Python's thread manager.

Quite difficult to manage on Windows.


 Richard


Re: [pygame] Networking?

2007-11-20 Thread Patrick Mullen
I tried the twisted as separate process thing for a while when i was
working with Blender's game engine.  At the time it was the only way I
knew how to do it, but it was very unwieldy to work with and deploy,
just not a good system at all.  You are already introducing issues
with network communication, why introduce issues with local
communication as well.

Currently I am using sockets with threads, it works pretty well I
think.  It seems extremely stable, and fast enough, if I could get my
higher level constructs in order.  The hard part with network
programming in my opinion is the higher level stuff rather than the
protocol.  How to serialize the data, what data to send, and how to
interpret it, is very difficult if you want a smooth game.  No
networking library I have seen handles this for you.  I'd like to see
someone write a game network library that handles things like moving
characters around and sending chat messages - 95% of networked games
need these two things.  But most games are so specialized and
integrated that it's hard to modularize this functionality to make it
general enough for a library.  If I ever completely solve my netcode,
I don't see myself being up to that task.

I used to really like twisted, but it's sort of a hard nut to crack
sometimes.  When using basically the raw tcp or udp protocols, twisted
seems like massive overkill to me, and none of it's constructs seem
all that well tailored to games.  That might have changed in the few
years I've been away though.  What things like raknet, hawkNL, etc
give you, is the ability for reliable udp sockets, which does make
some things a bit easier and smoother.

But really, the socket module IS everything you need.  It's just a lot
of work to set up and learn to use it.

On Nov 20, 2007 12:49 PM, Richard Jones [EMAIL PROTECTED] wrote:
 On Wed, 21 Nov 2007, David wrote:
  1)  Use Twisted with reactor.iterate

 I found that this approach has quite a high impact (ie. takes a considerable
 amount of time to run, even when there's no network events).


  2) Use the Twisted reactor *as* your main loop, and implement all game
  logic as call-backs from there. This is the approach that the Twisted
  people will recommend.

 This is also useless for highly interactive games.


   3) Run the Twisted reactor in its own thread

 This is probably the only reasonable approach for games.


  5)  Run the Twisted reactor in its own process, and use pipes or sockets to
  pass data between
  it and the main loop/process.  This has the merit of using the OS's CPU
  allocation management
  rather than that of Python's thread manager.

 Quite difficult to manage on Windows.


  Richard



Re: [pygame] Networking?

2007-11-20 Thread Michael Sparks
On Monday 19 November 2007 19:08:49 Jason Ward wrote:
 I want to make my game playable over the network and if possible the
 internet.
 For the network it must support more than 2 computers and be realtime
 Would the sockets library in python solve all my needs?

Simple outline of a networked pong game (just a networked bouncing ball :-)
using Kamaelia for networking and pygame:

http://kamaelia.svn.sourceforge.net/viewvc/kamaelia/trunk/Sketches/MPS/Pong.py?revision=3744view=markup

To run as a server:

# ./Pong.py server

To run the client (on the same machine)

# ./Pong.py 127.0.0.1

The server runs the game model and publishes to all clients. These need to be
serialised, so for the moment the message (ballpos, 100, 200) is serialised
as ballpos|100|200X. The X is needed as a record separator. This makes
the client slightly more complex. (Since the client needs to demarshall such
messages)

Other than that, that code is really divided into 4 parts.
   * A PygameComponent which simplfies using pygame. (To be merged at
     somepoint onto the mainline)
   * A component to handle display of scene objects
   * A component to handle updating the system model
   * A bunch of components declarations / pipelines to orchestrate behaviour.

The code in that example uses some newer features of Kamaelia (mainly to
assist readability), so if you want to try that code, you'll need to check
out my scratch branch:

svn co 
https://kamaelia.svn.sourceforge.net/svnroot/kamaelia/branches/private_MPS_Scratch

Then install Axon (which Kamaelia depends upon, then install Kamaelia) :

cd private_MPS_Scratch
cd Axon
sudo python setup.py install
cd ..
cd Kamaelia
sudo python setup.py install

Hope its of interest :-)


Michael.


Re: [pygame] Networking?

2007-11-20 Thread Jason Ward
Thanks for the options guys. I'll look into them when I find the time. But I
don't mind low-level stuff if that's what sockets library requires, just as
long as it can work. Surely there must be some good C/C++ library that I can
call with ctypes?
What about just calling the win32 api straight with ctypes to do all my
networking?
I looked into twisted but it's documentation is rather difficult and I hate
libraries that want the main loop, I prefer the control.


[pygame] Networking?

2007-11-19 Thread Jason Ward
I want to make my game playable over the network and if possible the
internet.
For the network it must support more than 2 computers and be realtime
Would the sockets library in python solve all my needs?


Re: [pygame] Networking?

2007-11-19 Thread Noah Kantrowitz
Not really. There isn't yet a good, lightweight networking library  
that plays well with pygame. Pyraknet is worth a look, as is Twisted,  
but both have their own problems. I've got some code I can throw your  
way, but it still has rough edges.


--Noah

On Nov 19, 2007, at 2:08 PM, Jason Ward wrote:

I want to make my game playable over the network and if possible the  
internet.

For the network it must support more than 2 computers and be realtime
Would the sockets library in python solve all my needs?




Re: [pygame] Networking?

2007-11-19 Thread Richard Jones
On Tue, 20 Nov 2007, Noah Kantrowitz wrote:
 Pyraknet is worth a look, as is Twisted,
 but both have their own problems.

Twisted is very mature, but can take some effort to learn how to use. It can 
also be very tricky to incorporate into a game.


Richard


Re: [pygame] Networking?

2007-11-19 Thread Simon Wittber
On Nov 20, 2007 4:08 AM, Jason Ward [EMAIL PROTECTED] wrote:
 I want to make my game playable over the network and if possible the
 internet.
 For the network it must support more than 2 computers and be realtime
 Would the sockets library in python solve all my needs?

http://www.google.com/search?q=simple+pygame+networking

Try the first link returned. :-)

-- 
:: Simon Wittber
:: http://www.linkedin.com/in/simonwittber
:: phone: +61.4.0135.0685
:: jabber/msn: [EMAIL PROTECTED]


Re: [pygame] pygame networking redux

2007-06-06 Thread Simon Wittber

So...

To summarise, it seems that people think Twisted is better than a
re-implementation, and that running the network loop can should be an
optional possibility.

It seems people are using PB with some success. Is an RPC-like system
such as PB preferable to a simple message/event passing system?


Re: [pygame] pygame networking redux

2007-06-05 Thread Toni Alatalo

Simon Wittber kirjoitti:

I think that is a matter of one's perspective on what is 'nice'.


sure seems like that.


Also, I don't really think it is such a big project. I've built this
sort of low level system before (using TCP instead of UDP) with higher
level stuff to pass dictionaries around in network messages... and


ok.. but,


they end up being  10k code, and much less intrusive than the twisted
reactor. (http://fibranet.googlecode.com/svn/trunk/nanotubes.py)


'intrusive'? as in .. filesize?

did not look at that code yet, will certainly check out, thanks for 
mentioning :)



I also want to use UDP, so I have more opportunities to tweak my
protocol to fit the way my games / app want to work.


I was also curious if there are ways to use Twisted with UDP, I actually 
thought/assumed there are.


Then again, we have not tested yet for the relatively-low-latency 
networking need we have for a game now, will be interesting to see if 
TCP cuts it -- if not, there are existing libs that use UDP for these 
kinds of things too, which we can test, if TCP, and hence some of the 
existing simple tools, is too slow. I planned to test TCP with Tofu 
first (the twisted, but not pb?, using thing from the folks who make 
soya3d (oomadness)), and then perhaps look at Verse and/or VOB from 
interreality.org .. then again I should first check what game libs there 
are, do remember that there were some folks use in some SDL games 
*googles a bit so you dont have to teach me* uh well game networking 
library gives a lot now.


Well, we'll proceed along that plan soon enough - am also interested to 
here and see how your things work.


~Toni




Re: [pygame] pygame networking redux

2007-06-05 Thread Phil Hassey
Another library worth considering is: http://pyraknet.slowchop.com/ - I haven't 
used it myself, but I've heard many good things about raknet.  It's a 
networking library written primarily for games.

Phil

Toni Alatalo [EMAIL PROTECTED] wrote: Simon Wittber kirjoitti:
 I think that is a matter of one's perspective on what is 'nice'.

sure seems like that.

 Also, I don't really think it is such a big project. I've built this
 sort of low level system before (using TCP instead of UDP) with higher
 level stuff to pass dictionaries around in network messages... and

ok.. but,

 they end up being  10k code, and much less intrusive than the twisted
 reactor. (http://fibranet.googlecode.com/svn/trunk/nanotubes.py)

'intrusive'? as in .. filesize?

did not look at that code yet, will certainly check out, thanks for 
mentioning :)

 I also want to use UDP, so I have more opportunities to tweak my
 protocol to fit the way my games / app want to work.

I was also curious if there are ways to use Twisted with UDP, I actually 
thought/assumed there are.

Then again, we have not tested yet for the relatively-low-latency 
networking need we have for a game now, will be interesting to see if 
TCP cuts it -- if not, there are existing libs that use UDP for these 
kinds of things too, which we can test, if TCP, and hence some of the 
existing simple tools, is too slow. I planned to test TCP with Tofu 
first (the twisted, but not pb?, using thing from the folks who make 
soya3d (oomadness)), and then perhaps look at Verse and/or VOB from 
interreality.org .. then again I should first check what game libs there 
are, do remember that there were some folks use in some SDL games 
*googles a bit so you dont have to teach me* uh well game networking 
library gives a lot now.

Well, we'll proceed along that plan soon enough - am also interested to 
here and see how your things work.

~Toni




   
-
Looking for a deal? Find great prices on flights and hotels with Yahoo! 
FareChase.

Re: [pygame] pygame networking redux

2007-06-05 Thread altern

hi

not sure if directly related to this but I find OSC protocol very 
interesting to send info over the net, it was developed as a replacement 
of MIDI, but it is just a network protocol as far as i understand. There 
are python bindings and I did a layer around the original bindings to 
simplify the api as much as possible.

http://www.ixi-software.net/content/download/simpleosc0.2.3.zip

I cannot find a link to the original OSC.py but it is included in the 
zip above in case you want to work directly with the sockets, etc...


enrike

Phil Hassey(e)k dio:
Another library worth considering is: http://pyraknet.slowchop.com/ - I 
haven't used it myself, but I've heard many good things about raknet.  
It's a networking library written primarily for games. **


Phil

*/Toni Alatalo [EMAIL PROTECTED]/* wrote:

Simon Wittber kirjoitti:
  I think that is a matter of one's perspective on what is 'nice'.

sure seems like that.

  Also, I don't really think it is such a big project. I've built this
  sort of low level system before (using TCP instead of UDP) with
higher
  level stuff to pass dictionaries around in network messages... and

ok.. but,

  they end up being  10k code, and much less intrusive than the
twisted
  reactor. (http://fibranet.googlecode.com/svn/trunk/nanotubes.py)

'intrusive'? as in .. filesize?

did not look at that code yet, will certainly check out, thanks for
mentioning :)

  I also want to use UDP, so I have more opportunities to tweak my
  protocol to fit the way my games / app want to work.

I was also curious if there are ways to use Twisted with UDP, I
actually
thought/assumed there are.

Then again, we have not tested yet for the relatively-low-latency
networking need we have for a game now, will be interesting to see if
TCP cuts it -- if not, there are existing libs that use UDP for these
kinds of things too, which we can test, if TCP, and hence some of the
existing simple tools, is too slow. I planned to test TCP with Tofu
first (the twisted, but not pb?, using thing from the folks who make
soya3d (oomadness)), and then perhaps look at Verse and/or VOB from
interreality.org .. then again I should first check what game libs
there
are, do remember that there were some folks use in some SDL games
*googles a bit so you dont have to teach me* uh well game networking
library gives a lot now.

Well, we'll proceed along that plan soon enough - am also interested to
here and see how your things work.

~Toni



Looking for a deal? Find great prices on flights and hotels 
http://us.rd.yahoo.com/evt=47094/*http://farechase.yahoo.com/;_ylc=X3oDMTFicDJoNDllBF9TAzk3NDA3NTg5BHBvcwMxMwRzZWMDZ3JvdXBzBHNsawNlbWFpbC1uY20- 
with Yahoo! FareChase.




Re: [pygame] pygame networking redux

2007-06-05 Thread 12 Dogs


I was also curious if there are ways to use Twisted with UDP, I actually
thought/assumed there are.

You can do UDP with twisted, but it's extremely underdeveloped, if you

have your heart set on UDP i'd probably suggest pretty much anything else.
Nathan


Re: [pygame] pygame networking redux

2007-06-05 Thread René Dudfield

There's also that P2P protocol in twisted I think.  It has a Q in the
name, but I can't find it or remember it.  It is supposed to be able
to handle things like NAT traversal too.


On 6/6/07, 12 Dogs [EMAIL PROTECTED] wrote:




 I was also curious if there are ways to use Twisted with UDP, I actually
 thought/assumed there are.


You can do UDP with twisted, but it's extremely underdeveloped, if you have
your heart set on UDP i'd probably suggest pretty much anything else.
Nathan



Re: [pygame] pygame networking redux

2007-06-05 Thread René Dudfield

I'm not sure this is true or not, but it's something I think is the
case (untested)...


It seems that running twisted in a separate thread would be better for
keeping more consistent latency in networking.

If you wanted to run your networking at different frequencies to the
rest of your system.  It seems that some of the time, this would be
the case.  Much like sound requires updating at  different
frequencies.

Iterating it at eg. 72fps means that the quickest data can go out is
at 1/72 messages per second?

If you don't have a consistent frame rate, say a frame too 1/14th of a
second because of some heavy graphics - then messages would only come
out every 1/14th of a second.

Whereas if you ran twisted in another thread it would be separate of
those concerns - and could run at a different frequency.  Maybe a
lower frequency even.

As a bonus all your networking stuff can be handled by a separate
CPU/Core if available.


Or am I way off here?  Maybe it doesn't matter.



On 6/6/07, Simon Wittber [EMAIL PROTECTED] wrote:

Richard Jones just mentioned to me off list how he is using twisted.
(He is having issues with the mailing list).

Using twisted like this is not intrusive, as it lets me keep control
of the main loop. Thanks Richard!



We've just run into this ourselves, but in our case integrating Twisted
into a pyglet application (though not into its event system yet - just
into the main loop).

The docs are extremely sparse in this area, but the following is mostly
working for us:

  reactor.startRunning(1)   (or 0 if you don't want it to take
over signals)
  while main_loop:
 reactor.iterate(0.01)

then when you want to exit your program, use:

   reactor.stop(); reactor.iterate(0.01)



Re: [pygame] pygame networking redux

2007-06-05 Thread Jasper
Perhaps useful.  Seems like premature optimization to me though, and 
unlikely to gain enough to be worth the pain of dealing with threads.


-Jasper

René Dudfield wrote:

I'm not sure this is true or not, but it's something I think is the
case (untested)...


It seems that running twisted in a separate thread would be better for
keeping more consistent latency in networking.

If you wanted to run your networking at different frequencies to the
rest of your system.  It seems that some of the time, this would be
the case.  Much like sound requires updating at  different
frequencies.

Iterating it at eg. 72fps means that the quickest data can go out is
at 1/72 messages per second?

If you don't have a consistent frame rate, say a frame too 1/14th of a
second because of some heavy graphics - then messages would only come
out every 1/14th of a second.

Whereas if you ran twisted in another thread it would be separate of
those concerns - and could run at a different frequency.  Maybe a
lower frequency even.

As a bonus all your networking stuff can be handled by a separate
CPU/Core if available.


Or am I way off here?  Maybe it doesn't matter.



On 6/6/07, Simon Wittber [EMAIL PROTECTED] wrote:

Richard Jones just mentioned to me off list how he is using twisted.
(He is having issues with the mailing list).

Using twisted like this is not intrusive, as it lets me keep control
of the main loop. Thanks Richard!



We've just run into this ourselves, but in our case integrating 
Twisted
into a pyglet application (though not into its event system yet - 
just

into the main loop).

The docs are extremely sparse in this area, but the following is 
mostly

working for us:

  reactor.startRunning(1)   (or 0 if you don't want it to take
over signals)
  while main_loop:
 reactor.iterate(0.01)

then when you want to exit your program, use:

   reactor.stop(); reactor.iterate(0.01)







Re: [pygame] pygame networking redux

2007-06-05 Thread Dave LeCompte (really)
René Dudfield [EMAIL PROTECTED] said:

 Iterating it at eg. 72fps means that the quickest data can go out is
 at 1/72 messages per second?

You probably don't mean this - 1/72 messages per second is awfully slow.


What I've done in situations like this before is to create an outgoing
message queue - as my game loop generates information that needs to go out
on the wire, it gets added to the queue. Then, after the game update, I do
my network housekeeping, which sends each message from the queue out
over the network. I also spend that time to pull all waiting traffic in
off the net - could be zero, one, or many messages waiting to be processed
inbound and outbound.


 If you don't have a consistent frame rate, say a frame too 1/14th of a
 second because of some heavy graphics - then messages would only come
 out every 1/14th of a second.

Yeah, providing a queue permits spiky circumstances to be handled as soon
as possible - though you may decide to limit the amount of traffic to move
in or out. For example, if you get a LOT of network traffic all at once (a
new player entering the game, sending out a lot of initial state
information in a short period of time), it's possible that processing all
of the waiting network messages in one frame could take too long, causing
a visible frame rate drop. So, instead, you might wish to choose a maximum
number of messages to process per frame.

 Whereas if you ran twisted in another thread it would be separate of
 those concerns - and could run at a different frequency.  Maybe a
 lower frequency even.

Yeah, the idea is tempting, but I'm nervous about multithreading,
particularly making sure the threads communicate correctly. There are a
number of approaches to getting that right (mutexes, lock free algorithms,
channels), but that sort of thinking hurts my brain, and I write games to
have fun. So I avoid threads unless they're far and away the best choice
for the job.

 As a bonus all your networking stuff can be handled by a separate
 CPU/Core if available.

That would be nice, but with current versions of Python (anything with a
Global Interpreter Lock - see, for example
http://docs.python.org/api/threads.html ), you're not going to get much
concurrency on multicore machines. I'm not sure, maybe there's some
benefit to be had with low-level networking I/O being processed
independently, but the python code will all be serialized (i.e. not
concurrent) because of that GIL.

If multithreaded Python networking really excites you, I suggest you take
a look at http://www.stackless.com - a modification of the Python
interpreter which permits a lot of stuff that I find fascinating, but
again, makes my brain hurt, so I've almost never tried to integrate the
ideas with game development.


I'm not saying threads can't be used to good effect, they just require my
brain to stretch in ways it's not comfortable with. If they work for you,
that's great.


-Dave LeCompte


[pygame] pygame networking redux

2007-06-04 Thread Simon Wittber

I've finally got some time to spend on building something useful for
pygame networking.

I've had a look at the latest Twisted (2.5), and it seems that there
is no longer any support for integrating the twisted event loop with
pygame. Bah.

Anyhow, I figure there is enough brains on this list for us to nut
something out, which is simple, and works on a variety of platforms.
So... if anyone is interested in helping out, please throw your 2c in.

I've attached my first thoughts in two .py files.

interface.py contains basic UDP class, and also contains classes
specific for each platform. (At this stage I'm not interested in
dealing with TCP connections)

pygnet.py contains a class for detecting missing packets in a
sequence, on a channel.

My idea is to build up layers of reliability using class inheritance,
so you can pick the class you need for the type of data you want to
send...

Once all this low-level stuff is done, we could add lobby systems,
score systems etc which are fairly generic and easily used across
different games/apps.

Anyone interested?




--
   :: Simon Wittber
   :: http://www.linkedin.com/in/simonwittber
   :: phone: +61.4.0135.0685
   :: jabber/msn: [EMAIL PROTECTED]

from socket import socket, AF_INET, SOCK_DGRAM, error
import sys


MAX_PACKET_SIZE = 1024

class BaseUDPInterface(object):
def __init__(self, address):
self.socket = socket(AF_INET, SOCK_DGRAM)
self.socket.bind(address)
self.socket.setblocking(0)

def handle_error(self, e):
pass

def handle_recv(self, address, packet):
pass

def poll(self):
try:
packet, address = self.socket.recvfrom(MAX_PACKET_SIZE)
except error, e:
self.handle_error(e)
else:
self.handle_recv(address, packet)

def send(self, address, packet):
try:
self.socket.sendto(packet, address)
except error, e:
self.handle_error(e)


if sys.platform[:5] == 'linux':
class UDPInterface(BaseUDPInterface):
def handle_error(self, e):
pass 

elif sys.platform[:3] == 'win':
class UDPInterface(BaseUDPInterface):
def handle_error(self, e):
pass 
import struct

from interface import UDPInterface

class UnreliableInterface(UDPInterface):
def __init__(self, *args, **kw):
UDPInterface.__init__(self, *args, **kw)
self.outbound_channels = {}
self.inbound_channels = {}

def dispatch(self, channel, address, data):
pass

def send(self, address, channel, data):
seq_id = self.outbound_channels.get(channel, 0)
self.outbound_channels[channel] = seq_id + 1
packet = struct.pack(!ii, channel, seq_id) + data
UDPInterface.send(self, address, packet)

def handle_missing(self, recieved_id, expected_id):
pass

def handle_recv(self, address, data):
channel, seq_id = struct.unpack(!ii, data[:8])
expected_seq_id = self.inbound_channels.get(channel, 0)
if seq_id != expected_seq_id:
self.handle_missing(seq_id, expected_seq_id)
self.inbound_channels[channel] = seq_id + 1
data = data[8:]
self.dispatch(channel, address, data)


class ReliableInterface(UnreliableInterface):

This class needs to track sent packets, handle resend conditions etc.

pass



if __name__ == __main__:
s = UnreliableInterface(('127.0.0.1',1999))
c = UnreliableInterface(('127.0.0.1',1992))
for i in xrange(1000):
s.send(('127.0.0.1',1992), 0, 'blah'*1000)
s.poll()
c.poll()


Re: [pygame] pygame networking redux

2007-06-04 Thread Simon Oberhammer

I've had a look at the latest Twisted (2.5), and it seems that there
is no longer any support for integrating the twisted event loop with
pygame. Bah.




() Once all this low-level stuff is done, we could add lobby systems,
score systems etc which are fairly generic and easily used across
different games/apps.



I'm not so sure I understand what you want your self-made lowlevel classes
to do, but I have been using twisteds perspective broker (sort of RPC) for
all my networking needs. I made a NetworkController class that works with PB
calls and feeds the network-events into the local event queue not truely
into the real pygame-event-queue, but I guess that wouldn't be too tough to
extend.

I apologize if I totally misunderstood what you are trying to do but working
with sockets is bäähh, I'd rather build on twisted for any networking needs.

greetings


Re: [pygame] pygame networking redux

2007-06-04 Thread Simon Oberhammer

ba:a:hh ???



I play on SimonW's  bah in german... the : should be on top of the a if
you email client supports it :-)


Re: [pygame] pygame networking redux

2007-06-04 Thread Simon Wittber

On 6/5/07, Simon Oberhammer [EMAIL PROTECTED] wrote:

I apologize if I totally misunderstood what you are trying to do but working
with sockets is bäähh, I'd rather build on twisted for any networking needs.


I'm still undecided on Twisted. I haven't done any serious work with
it since 1.3. Looking at the current docs however, I can't see how to
iterate the pygame event queue at the same time as run the
reactor.run() call.

How do you process your pygame event queue?


--
   :: Simon Wittber
   :: http://www.linkedin.com/in/simonwittber
   :: phone: +61.4.0135.0685
   :: jabber/msn: [EMAIL PROTECTED]


Re: [pygame] pygame networking redux

2007-06-04 Thread 12 Dogs

Don't know if this will be helpful, but a while ago i started writing a
lemmings clone using twisted for networking.  the file in question is
available here: http://thescarydoor.googlecode.com/svn/trunk/default.py i
didn't have much problems with the twisted loop and the event code, i just
didn't use the event loop.  The only other option is to use twisted in a
second thread which can get a little messy but not too bad as it's just 1
thread.
Nathan

On 6/5/07, Simon Wittber [EMAIL PROTECTED] wrote:


On 6/5/07, Simon Oberhammer [EMAIL PROTECTED] wrote:
 I apologize if I totally misunderstood what you are trying to do but
working
 with sockets is bäähh, I'd rather build on twisted for any networking
needs.

I'm still undecided on Twisted. I haven't done any serious work with
it since 1.3. Looking at the current docs however, I can't see how to
iterate the pygame event queue at the same time as run the
reactor.run() call.

How do you process your pygame event queue?


--
:: Simon Wittber
:: http://www.linkedin.com/in/simonwittber
:: phone: +61.4.0135.0685
:: jabber/msn: [EMAIL PROTECTED]



Re: [pygame] pygame networking redux

2007-06-04 Thread Jasper

Simon Wittber wrote:

Ah I can see how you solved the problem:

def main(self):
self.checkEvents(pygame.event.get())

... snip lots of code ...

#come back here at a rate of approx 30fps
reactor.callLater(0.03, self.main)

Basically you asked twisted to call your function, and when your
function finishes, you ask twisted to call it again.

I'd prefer not to use twisted this way. It turns what should be a
simple, tight inner loop into a function call which has to work its
way through twisted's scheduling mechanics for every frame.

-Sw.




This is essentially what I do, yielding 60 frames/second of 3D and 
animation without any trouble.  I don't think the twisted overhead is as 
big as you fear, and it's definitely several orders of magnitude nicer 
than dealing with low level networking protocols.  It has been easily 
fast enough, Perspective Broker saved me from (re)writing tons of code, 
and I've undoubtedly avoided plenty of nasty networking bugs as well.


What would you hope to gain by rolling your own networking code?

-Jasper


Re: [pygame] Re: pygame networking

2006-06-05 Thread Rene Dudfield

Hello,

You can't kill a thread in python.

Check out the sockets page in the docs for some ways around blocking.
http://docs.python.org/lib/socket-objects.html

There's some options on python sockets for settimeout, and
setblocking.  So you can use non blocking stuff inside a thread too.

For debugging threaded programs it is useful to be able to run all of
the code within one thread if possible.  That way you can take the
threading issues out of the debugging.  As with one thread, your
program is serial again.

Check out flup for one example of a threaded server...
http://svn.saddi.com/flup/  It uses a threadpool.


On 6/6/06, Bryce Allen [EMAIL PROTECTED] wrote:

I have Trac/svn for my pygame networking project, courtesy of webfaction.com.
Here is the URL:

http://pygamenetworking.python-hosting.com

I haven't had much time to work on the project, but I did post some code. At
the moment I'm trying to figure out how to properly kill off a thread that's
blocking on socket calls. Does anyone have a simple example of threading with
the python socket API?

Thanks,
Bryce