Dear everyone, I have the following server running:
class ThasherProtocol(basic.LineReceiver):
def lineReceived(self, line):
dic = simplejson.loads( line)
ret = self.factory.d[ dic['method'] ]( dic['args'] )
self.transport.write( simplejson.dumps( ret) )
self.transport.loseConnection()
class ThasherFactory(ServerFactory):
protocol = ThasherProtocol
def __init__(self):
self.thasher = Thasher()
self.d= {
'getHash': self.thasher.getHash,
'sellHash' : self.thasher.sellHash
}
reactor.listenUNIX( c.LOCATION_THASHER, ThasherFactory() )
reactor.run()
I have multiple files importing a special function called "getHash" from a particular file. Note that getHash's arguments are only gonna be a dictionary of texts (strings). How do I write a client function (getHash) that can be simply:
from particular file import getHash
i = getHash( { 'type':'url', 'url':'http://www.stackoverflow.com' } )
Note that ALL I WANT TO DO is: 1) dump a dict into json, 2) dump that json into the particular socket, 3) wait for that to come back and unpack the json