Advertisement
Dernhelm

wbasicClient.py

Jun 19th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. from twisted.spread import pb
  4. from twisted.internet import reactor
  5.  
  6. def main():
  7.    cFunc = Cfunc()
  8.    f = pb.PBClientFactory()
  9.    reactor.connectTCP("localhost", 1025, f) #open connection
  10.    f.getRootObject().addCallbacks(cFunc.start, cFunc.error)
  11.    reactor.run()
  12.  
  13. class Cfunc(pb.Referenceable):
  14.  
  15.     #start server and client waiting for input
  16.     def start(self, objS1):
  17.         objS1.callRemote('talks', self)
  18.  
  19.     #take input and print on client and server.
  20.     def remote_talkc(self, objS1):
  21.         #ask for input FROM SERVER (?)
  22.         l = objS1.callRemote('listen')
  23.         #when received, print
  24.     l.addCallback(self.hear)
  25.     #...and start the process over again...
  26.     self.start(objS1)
  27.  
  28.     def remote_listen(self):
  29.         message = raw_input('c: ')
  30.         return message
  31.                                      
  32.     def hear(self, message):
  33.     print "Client heard: "
  34.     print message
  35.  
  36.     def error(self, reason):
  37.         print "Remote exception: "
  38.     print reason
  39.     reactor.stop()
  40.  
  41. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement