Advertisement
Dernhelm

wbasicServer.py

Jun 19th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 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.     l.addErrback(self.error)
  26.     #...and start the process over again.
  27.     self.start(objS1)
  28.  
  29.     def remote_listen(self):
  30.         message = raw_input('c: ')
  31.         return message
  32.                                      
  33.     def hear(self, message):
  34.     print "Client heard: "
  35.     print message
  36.  
  37.     def error(self, reason):
  38.         print "Remote exception: "
  39.     print reason
  40.     reactor.stop()
  41.  
  42. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement