using Pyro for network games

garabik-news-2005-05 at kassiopeia.juls.savba.sk garabik-news-2005-05 at kassiopeia.juls.savba.sk
Fri Aug 5 03:27:00 EDT 2005


Michael Rybak <accepted at ukr.net> wrote:
> gn20kjss> Do not use pyro, use simple UDP protocol.
> gn20kjss> I've written networked tetris in python, communicating via
> gn20kjss> UDP protocol, and used it successfully on very congested lines.
> 
> Would you please be so kind to share that with me? That would be

http://melkor.dnp.fmph.uniba.sk/~garabik/pytris.html

contrary to what the page says, you do not need pyncurses, just plain
curses as included with modern pythons

> greatly helpful, because 1) I'd run it together with my friend to see
> what speed I can get from UDP 2) I'd grasp the networking part of your
> code and reuse it.

see the Net() class. I recommend you to use the same number for myport
and otherport (you can with UDP, and it makes traversing firewalls
easier)

> 
> gn20kjss> If all you need is to transfer pointer coordinates, UDP is perfect since
> gn20kjss> you do not need feedback.
> 
> gn20kjss> use something like this for server:
> 
> gn20kjss> import socket
> gn20kjss> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> gn20kjss> s.bind(('', port))
> gn20kjss> while 1:
> gn20kjss>     data, addr = s.recvfrom(1024)
> gn20kjss>     print `data`
> 
> 
> gn20kjss> and for client:
> 
> gn20kjss> import socket
> 
> gn20kjss> outsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> gn20kjss> outsock.bind(('', 0))
> gn20kjss> outsock.sendto('message', ('server-hostname', server_port))
> Would you recommend some reading on this? I have some immediate

just the socket.socket documentation, and generally for UDP protocol, 
see e.g. http://www-net.cs.umass.edu/kurose/transport/UDP.html

Using it is very simple, on one computer, you send a (short) string,
and on the other computer you receive the string (or it might be lost on
the way). For your situation, I'd recommend to implement some sort of
time constrain - e.g. if user moves cursor very fast, ensure that the
coordinates are not transmitted with higher frequency that 50 Hz (or
something). And combine the coordinates into one packet - it always
helps to reduce the number of packets. 

> questions to your code, but don't want to flood here. OK, I will flood
> here a bit: what's the print `` syntax?

the same as repr, i.e. textual representation of a variable - good for
debugging

> 
> P.S. I loved your virus alert ;)
> 

and you got infected I see :-)

-- 
 -----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
 -----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!



More information about the Python-list mailing list