473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using Pyro for network games

Hi, everyone.
In topic "2-player game, client and server at localhost", I've asked
about subj, and Peter Hansen suggested to switch to Twisted, Pyro or
the like.

I've tried using Pyro.

I've written a very very simple test-game, in which you have 2 balls
controlled by 2 players. Each player moves his mouse somewhere at
his window, and his ball starts moving towards the pointer. No
objectives, just to test how it works. The code is very small, so I
can put it all here, skipping obvious stuff.

I've tried playing this test-game via local-host - all is ok.
Then I've tested via Internet connection with my friend. I have a
33.6 Kbps modem, he has a 2 MBps dedicated line (if this is the term),
and we ran a server at his pc and both connected to it. His ball ran as
a child, smoothly and quickly, while I had about 5 fps :(, and for him
it looked like my ball is simply very slow. I realise that client at
my pc *has* to work slower than the client at server's pc, but hey,
I've played Quake2 and WarCraft 2 via 33.6 modem, and those should have
much more stuff to transfer per second :(

Please help me in any way you can think of. I'd welcome links to
Python games written with Pyro, tips on what I am doing wrong, on not
Pythonically enough - anything.

############### #############se rver.py######## #########
#
[..imports..]
class game__(game_, Pyro.core.ObjBa se):
def __init__(self):
#storage for balls' coordinates
game_.__init__( self)
Pyro.core.ObjBa se.__init__(sel f)

[..server initialization. .]

daemon.requestL oop()
END############ #############se rver.py######## #########

############### #############cl ient.py######## #########
[..imports..]

[..preparations to create proxy..]
proxy=Pyro.core .getAttrProxyFo rURI(URI)

[..imports..]

def process_user_in put(game, id):#id is client's id - 0 or 1
nx, ny = pygame.mouse.ge t_pos()
x, y = game.ball[id].get_pos()
dx, dy = nx - x, ny - y
leng = sqrt(dx*dx + dy*dy)
k = 20 / leng
dx *= k
dy *= k
game.move(id, dx, dy) #remote call: move ball
id = proxy.get_n_cli ents() #which ball to control
if id < 2:
proxy.new_clien t()

pygame.init()
scr = pygame.display. set_mode((640, 480))

g = game(proxy.get_ status(), scr)
#get_status provides 2 pairs of balls's current coordinates
#g, "game" instance, is a local storage, able to render itself

while 1:
g.set_status(pr oxy.get_status( ))
g.render()
process_user_in put(proxy, id)

time.sleep(0.03 )

[..quit = (ESCAPE is pressed)..]
if quit: break

END############ #############cl ient.py######## #########

--
Best Regards,
Michael Rybak mailto:ac****** @ukr.net

Aug 1 '05 #1
3 1929
Michael Rybak <ac******@ukr.n et> wrote:
Hi, everyone.
In topic "2-player game, client and server at localhost", I've asked
about subj, and Peter Hansen suggested to switch to Twisted, Pyro or
the like.

I've tried using Pyro.

I've written a very very simple test-game, in which you have 2 balls
controlled by 2 players. Each player moves his mouse somewhere at
his window, and his ball starts moving towards the pointer. No
objectives, just to test how it works. The code is very small, so I
can put it all here, skipping obvious stuff.

I've tried playing this test-game via local-host - all is ok.
Then I've tested via Internet connection with my friend. I have a
33.6 Kbps modem, he has a 2 MBps dedicated line (if this is the term),
and we ran a server at his pc and both connected to it. His ball ran as
a child, smoothly and quickly, while I had about 5 fps :(, and for him
it looked like my ball is simply very slow. I realise that client at
my pc *has* to work slower than the client at server's pc, but hey,
I've played Quake2 and WarCraft 2 via 33.6 modem, and those should have
much more stuff to transfer per second :(

Please help me in any way you can think of. I'd welcome links to
Python games written with Pyro, tips on what I am doing wrong, on not
Pythonically enough - anything.

Do not use pyro, use simple UDP protocol.
I've written networked tetris in python, communicating via
UDP protocol, and used it successfully on very congested lines.
If all you need is to transfer pointer coordinates, UDP is perfect since
you do not need feedback.

use something like this for server:

import socket
s = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
s.bind(('', port))
while 1:
data, addr = s.recvfrom(1024 )
print `data`
and for client:

import socket

outsock = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
outsock.bind((' ', 0))
outsock.sendto( 'message', ('server-hostname', server_port))

--
-----------------------------------------------------------
| 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!
Aug 2 '05 #2
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
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.

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(s ocket.AF_INET, socket.SOCK_DGR AM)
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(s ocket.AF_INET, socket.SOCK_DGR AM)
gn20kjss> outsock.bind((' ', 0))
gn20kjss> outsock.sendto( 'message', ('server-hostname', server_port))
Would you recommend some reading on this? I have some immediate
questions to your code, but don't want to flood here. OK, I will flood
here a bit: what's the print `` syntax?

P.S. I loved your virus alert ;)
gn20kjss> --
gn20kjss> -----------------------------------------------------------
gn20kjss> | Radovan Garabik http://kassiopeia.juls.savba.sk/~garabik/ |
gn20kjss> | __..--^^^--..__ garabik @ kassiopeia.juls .savba.sk |
gn20kjss> -----------------------------------------------------------
gn20kjss> Antivirus alert: file .signature infected by signature virus.
gn20kjss> Hi! I'm a signature virus! Copy me into your signature file to help me spread!

--
Best Regards,
Michael Rybak mailto:ac****** @ukr.net
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!

Aug 2 '05 #3
Michael Rybak <ac******@ukr.n et> 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(s ocket.AF_INET, socket.SOCK_DGR AM)
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(s ocket.AF_INET, socket.SOCK_DGR AM)
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!
Aug 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
7625
by: jblazi | last post by:
How do I find out my own IP number (using Pythoi of course). And how do I send/receive data to/from andother TCP/IP socket (of known ip number)? I mean: which module do I have to use for that? TIA, JB
1
1507
by: hyperbob | last post by:
Hi, I'm working on a distributed application using Pyro, and I've come across several issues I'm not really sure how to handle, since this is my first distributed application. My application consists of several servers supplying various functions. They require a name server to be running first. How do I make it run? What if another application has already set up a pyro name server (because if I use such a server it could be shut down
5
1360
by: secun | last post by:
Has anyone used python to deploy (non-python) software on a Windows network?
0
1329
by: adam | last post by:
I'm using Pyro to develop a distribuited system running my integration test suite I've found a strange behaviour it seems that whenever I have a failed resolve or unregister on a name server, the name server acts normally during its life span, but when I shut it down... something remains up... if, afterwards, i lookup for a name server python freezes
3
1862
slapshock
by: slapshock | last post by:
hello!!! i have a problem, i dont know how to network games that is created in vb6... please help me on how to do it.... what are the components that i can use in order for the system to work in network... tnx
2
2276
by: =?ISO-8859-1?Q?S=E9bastien_Ramage?= | last post by:
Hi ! I'm trying to build an client/server app based on Pyro and sqlite3. But I have a problem using sqlite3 on the server I got this error : sqlite3.ProgrammingError: ('SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 240 and this
2
3872
by: jamitwidme | last post by:
Hello everyone Can someone help me fix this problem? I am using an example from Pyro(Python Remote Object) website directly. It is the last example from http://pyro.sourceforge.net/manual/8-example.htm I have two computers to run Server and Client. ############################################
0
979
by: hussain3047 | last post by:
Hi I want to upload a single file via FTP through different network adapters or WAN connections I will break the file into several small pieces and upload it to a single destination through FTP, but through different network adapters (WAN connections) I just want to know can I upload one piece through one adapter and the other piece through another adapter programmatic-ally..? Thanks in advance.
8
8372
by: tvnaidu | last post by:
consumer appliance device with ethernet (RJ45) interface can be plug into home router or office router within that LAN, local DHCP server assigns IP address with that LAN, this contains web interface to configure device (if its IP address is 192.168.0.66, this can be accesses using http://192.168.0.66), how can this device access from outside home, for example public places where internet available (starbucks, bnookshop, Cafe, public library...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.