Simple RPC server and client

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Simple RPC server and client

Post 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

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post 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:

User avatar
CyberPulse
On the way to fame!
On the way to fame!
Posts: 36
Joined: 10 Aug 2005, 16:00
18

Post 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.

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Hey Thanks

Post 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

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Hello

Post 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

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

OMG

Post 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

Post Reply