Page 1 of 1

Simple RPC server and client

Posted: 11 Sep 2005, 12:00
by maboroshi
Hi I am just playing around with code to see what I come up with

I came up with a server and client using XMLRPC

but I am having troubles I get an error when running the command from the client everything runs fine but when executing the function from the client I get an Error I have tried other simpler functions also like pow(x, y) I get the same error

anyway here is the code anyone who can help would be appreciated

cheers

Yes Python again all you java programmers must hate me

THe Server

Code: Select all


import pygame
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from SocketServer import ForkingMixIn
class Math:
    def cdEject():
        pygame.cdrom.init()
        print "CDROM initialized: ", pygame.cdrom.get_init()
        print "Number of CDROMs:  ", pygame.cdrom.get_count()
        cd_object.init()
        cd_object.eject()

class ForkingServer(ForkingMixIn, SimpleXMLRPCServer):
    pass

serveraddr = ('', 8765)
srvr = ForkingServer(serveraddr, SimpleXMLRPCRequestHandler)
srvr.register_instance(Math())
srvr.register_introspection_functions()
srvr.serve_forever()

And the client

Code: Select all



import xmlrpclib, code

url = 'http://localhost:8765/'
s = xmlrpclib.ServerProxy(url)

interp = code.InteractiveConsole({'s': s})
interp.interact("Use s to interact with the App")

and the error

Traceback (most recent call last):
File "<console>", line 1, in ?
File "F:\Python24\lib\xmlrpclib.py", line 1096, in __call__
return self.__send(self.__name, args)
File "F:\Python24\lib\xmlrpclib.py", line 1383, in __request
verbose=self.__verbose
File "F:\Python24\lib\xmlrpclib.py", line 1137, in request
headers
ProtocolError: <ProtocolError for localhost:8765/: -1 >


ANy Ideas cheers

Posted: 12 Sep 2005, 06:51
by bad_brain
Nah, Java coders just hate one thing: Java! :lol:
I´m sorry I can´t help you with this, I hope Cyberpulse will show up soon, he surely can give you some tips... :wink:

Posted: 12 Sep 2005, 16:49
by CyberPulse
Back again, doing a whole lot of stuff relating to work. Anyways, this one seems to be a little bit too difficult for me. I passed along the code to some of my coder friends. I'll let you know what they tell me. Sorry that I couldn't help you with this one.

Hey Thanks

Posted: 12 Sep 2005, 17:07
by maboroshi
Hey no prob about that

not even sure if the function works

just playing around

but I would like to troubleshoot the error so I can play some more

anyway cheers

Hello

Posted: 13 Sep 2005, 11:33
by maboroshi
Well I fixed my problem I forgot I was on a windows box lol

here is the code

it still doesn't work having problems ejecting the cd

any ideas

Cheers

the Server

Code: Select all


import pygame
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from SocketServer import ThreadingMixIn
class theApp:
    def cdEject(self):
        pygame.cdrom.init() 
        self.CD = pygame.cdrom.CD(0) 
        self.CD.init() 
        self.CD.eject()

class ThreadingServer(ThreadingMixIn, SimpleXMLRPCServer):
    pass

serveraddr = ('', 9000)
srvr = ThreadingServer(serveraddr, SimpleXMLRPCRequestHandler)
srvr.register_instance(theApp())
srvr.register_introspection_functions()
srvr.serve_forever()

The Client

Code: Select all


import xmlrpclib, code

url = 'http://localhost:9000/'
s = xmlrpclib.ServerProxy(url)

interp = code.InteractiveConsole({'s': s})
interp.interact("Use s to interact with the App")
Cheers

OMG

Posted: 13 Sep 2005, 11:57
by maboroshi
Holy

I just tested my code once more it ejects the cd SWEEEET

cool

I do get an error but the code works

Awesome

anyway this leads into bigger and better things now with my coding skills

Yes

tty guys later