Advertisement
Guest User

Code

a guest
Nov 2nd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import sys
  2. import time
  3. import logging
  4. from twisted.internet import reactor
  5. from autobahn.websocket import WebSocketClientFactory, \
  6.                                WebSocketClientProtocol, \
  7.                                connectWS
  8. from twisted.internet import inotify
  9. from twisted.python import filepath
  10.  
  11. class connection :
  12.     def __init__(self):
  13.         factory = WebSocketClientFactory("ws://localhost:8888/ws", debug=False)
  14.         factory.protocol = self.webSocket
  15.         connectWS(factory)
  16.         notifier = inotify.INotify()
  17.         notifier.startReading()
  18.         notifier.watch(filepath.FilePath("/home/amanush"), callbacks=[self.webSocket.notify])
  19.     def retrievePrivateKey (self):
  20.         return True
  21.     def retrievePublicKey (self):
  22.         return True
  23.     class webSocket(WebSocketClientProtocol):
  24.         def sendHello(self):
  25.             pass
  26.  
  27.         def onOpen(self):
  28.             self.sendHello()
  29.  
  30.         def onMessage(self, msg, binary):
  31.             print "Got echo: " + msg
  32.             reactor.callLater(1, self.sendHello)
  33.  
  34.         def notify(ignore, filepath, mask):
  35.             print "CALLBACK"
  36.             #print "event %s on %s" % (', '.join(inotify.humanReadableMask(mask)), filepath)
  37.  
  38. if __name__ == '__main__':
  39.     conn = connection()
  40.     reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement