pyro4+stackless how to send back data/commands?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2519 Views - Last Post: 30 September 2011 - 10:33 PM Rate Topic: -----

#1 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 02:42 AM

heyo all,

I am working on a multiplayer game using stackless python and Pyro4 and i have run into a wall.

It has all been working great and has been a blast to code with and i have learned a lot however i am having problems with figuring out a way to send commands or data back to the client from the server.

I can use the client to run a command on the server that spawns a new stackless tasklet and does things but i need the commands to be able to return things from the server you see. I have an object that can take a username from a client and adds that to the list of players as well as giving that username a unique ID so that all subsequent commands can be issued with that ID for that specific player however i cannot return that ID number back to the client from the server without doing 1 of 2 things which i really do not want to do:

1: i could make a pyro daemon on the client so the server might be able to remotely call functions on the client and pass data to them just like the server does but the lesser reason i do not want to do this is i believe it would be hard and messy to make every client register as an open daemon for pyro to connect with and would probably require the end user do some port forwarding. but the major reason is that the end user would have to have python installed and also have pyro4 installed so that they can run their own nameserver and this is just too messy for the average player to do.

2: i could ditch the stackless part and make it just use pyro and although this might be fine for a server running a few people on it that would rarely issue a command at the same time, the game is intended to do the exact opposite, that is its meant to have hundreds of people on it all issuing commands at the same time and this is the main reason i have chosen to use stackless!

i can provide specific code examples of the issue if necessary i just don't know where to go from here... this is my first multiplayer game though so i might be missing something very obvious but i am really rather set on using stackless and pyro and i do not see a way to send back commands or data to the client. also i understand that because this not only uses, what i believe to be, an obscure/unused library and version of python (being stackless and all (not much documentation on stackless)) makes asking for help very hard and limits the amount of people qualified to respond i will take any good ideas at this point.

so yeah sorry for being long winded and all but i would appreciate the help and ideas of my fellow DIC heads with this.
Nekroze

This post has been edited by Nekroze: 27 September 2011 - 02:44 AM


Is This A Good Question/Topic? 0
  • +

Replies To: pyro4+stackless how to send back data/commands?

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 06:33 AM

Having never use Pyro 4, but being familiar with the concept, please take my suggestions with a grain of salt.

You'll want to have your clients register themselves with the server when they start up. From there, the server can perform callbacks on the clients in order to pass data back. Perhaps withing the stackless tasklet.

class Client:
    ...
    def register(self):
        self.server.register(self)
    def print_data(self, data):
        print(data)
...
class Server:
    def register(self, client):
        self.clients.append(client)
    def print_data(self, data):
        for client in self.clients:
            client.print_data(data)



The Pyro 4 documentation has a stock ticker tutorial that should provide a more concrete example of remote callbacks. I can't attest to its compatibility with stackless however.

This post has been edited by Motoma: 27 September 2011 - 06:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 01:26 PM

the problem with the stock ticker example is that although all three parts can be run on separate computers each computer MUST run a pyro4 nameserver in a separate terminal to the actual script/code to use it and this requires a lot of things from the user that i really want to avoid (having python installed for instance, then installing the right libraries and all that (i solve this atm by using cx_Freeze)) so doing that is hardly an option.

I can see how your code would work if well enough if i was to make all users do all the low level python stuff just to run the client but i want a neat exe at the end not having people run multiple terminals and installing python (possibly a different version to what they have and different library versions aswell) cause in any game no matter how good this is a bit of a stretch to ask the average user to do just to play see.
Was This Post Helpful? 0
  • +
  • -

#4 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 03:19 PM

They each require their own name server? Are you sure about this? They can't all use the same name server?
Was This Post Helpful? 0
  • +
  • -

#5 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 03:40 PM

I don't know, as far as I have seen and done each computer needs a nameserver but it may work just need to portforward for internet play I would assume... well then I will go do a few proof of concepts, the naming might be a tad annoying but should be fine.

will come back with the results yeah, thanks motoma.
Was This Post Helpful? 0
  • +
  • -

#6 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 04:07 PM

OK, so after some testing on my local network i have ran into an errno 10049, that is "the request address is not valid in its context" all i have done is, just as i do when the nameserver is working on the same computer as the server script, told the pyro4 daemon that the host is my other computer the moment the daemon starts it throws this error so idk there should be a way of doing it though.
Was This Post Helpful? 0
  • +
  • -

#7 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 04:41 PM

With socket programming, that usually means you're trying to bind to a bad address a name that can't be resolved.

And by bind, I meant connect.
Was This Post Helpful? 0
  • +
  • -

#8 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 04:47 PM

that much of the error i get but it can bind that address fine if i use it to request functions from the nameserver it is just assigning the daemon to it that fails remotely. i just don't know how to do it, maybe it is my definition of the address, currently i have it as
daemon = Pyro4.Daemon(host = "192.168.1.7")

perhaps i should make it include the port 192.168.1.7:9090 but considering that is the default port it shouldn't need it. the address name should be fine thought as it binds fine when it is on the same computer as the nameserver.

EDIT: ok after putting the port at the end like i say above i get a tad further but i get a errno 11001 getaddrinfo failed.

This post has been edited by Nekroze: 27 September 2011 - 05:15 PM

Was This Post Helpful? 0
  • +
  • -

#9 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 05:33 PM

If you don't specify a port (via the port named argument to Daemon), it defaults to 0, meaning it will pick a random port.
Was This Post Helpful? 0
  • +
  • -

#10 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 05:42 PM

but in the latest test i did indeed define the port as well but it gave the new error.
Was This Post Helpful? 0
  • +
  • -

#11 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 05:50 PM

Like so?
daemon = Pyro4.Daemon(host="192.168.1.7", port=9090)


Was This Post Helpful? 0
  • +
  • -

#12 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 27 September 2011 - 06:00 PM

yeah that is a step back to the errno 10049, it seemded to respond better when i did:
daemon = Pyro4.Daemon(host="192.168.1.7:9090")


thats what i did to get the errno 11001.
Was This Post Helpful? 0
  • +
  • -

#13 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 28 September 2011 - 06:32 AM

Error 11001 is actually a failure earlier in the line from 10049. Where 10049 means you aren't able to connect, 11001 means you can't resolve a name to begin connecting.

I think it's time you post your code. I'll tinker around with it and see if I can find your problem.

Also let me know which version of Python you are using.
Was This Post Helpful? 0
  • +
  • -

#14 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: pyro4+stackless how to send back data/commands?

Posted 28 September 2011 - 03:21 PM

the code is just super simple test for it so sure here it is:

on my work terminal:
python -m Pyro4.naming -n 192.168.1.7

this just makes the nameserver on my machine and gives it my lan IP so i can use it over my LAN (which works for my normal client server stuff when the other computer is not starting a daemon just requesting functions) and i believe it would work on internet if i either portforward this ip to the internet or change my lan ip to my internet ip but that is another story.

on the second computer:
def test():
    print"!TEST!"

pyrodaemon = Pyro4.Daemon(host="192.168.1.7", port=9090)
Pyro4.Daemon.serveSimple(
    {
        test: "test:test"
    },
    daemon = pyrodaemon
    ns=True)

however the code fails at the creation of the pyrodaemon and ofc then cannot actualy create the serveSimple daemon which exposes the function to the remote server.

I am using stackless python 2.6.5 with pyro4.9, one problem with this that i can see is that pyro4.9 can be used by any version of python later then 2.6.5 including 3 so maybe it is assuming 3 and that is causing my problem however all the code and examples and all that has worked perfectly thus far so idk.

thanks again mate.
Was This Post Helpful? 0
  • +
  • -

#15 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: pyro4+stackless how to send back data/commands?

Posted 29 September 2011 - 06:45 AM

For me, this works:

python -m Pyro4.naming -n 192.168.1.7


def test():
    print"!TEST!"

pyrodaemon = Pyro4.Daemon(host="192.168.1.7")
Pyro4.Daemon.serveSimple(
    {
        test: "test:test"
    },
    daemon = pyrodaemon
    ns=True)



What OS are you on?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2