Advertisement
Guest User

snep-receive-and-put-twice

a guest
Sep 20th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: latin-1 -*-
  3.  
  4. import sys, os, argparse
  5.  
  6. sys.path.insert(1, os.path.split(sys.path[0])[0])
  7. from cli import CommandLineInterface
  8.  
  9. import nfc
  10. import nfc.snep
  11.  
  12. class SnepEchoServer(nfc.snep.SnepServer):
  13.     def __init__(self, llc):
  14.         nfc.snep.SnepServer.__init__(self, llc, "urn:nfc:sn:snep")
  15.         self.snep_client = nfc.snep.SnepClient(llc)
  16.  
  17.     def put(self, ndef_message):
  18.         print "received NDEF message"
  19.         print ndef_message.pretty()
  20.         self.snep_client.connect("urn:nfc:sn:snep")
  21.         self.snep_client.put(nfc.ndef.Message(
  22.             nfc.ndef.SmartPosterRecord('http://nfcpy.org')))
  23.         self.snep_client.put(nfc.ndef.Message(
  24.             nfc.ndef.SmartPosterRecord('http://google.com')))
  25.         self.snep_client.close()
  26.         return nfc.snep.Success
  27.  
  28. class Main(CommandLineInterface):
  29.     def __init__(self):
  30.         parser = argparse.ArgumentParser()
  31.         super(Main, self).__init__(
  32.             parser, groups="llcp dbg clf")
  33.  
  34.     def on_llcp_startup(self, clf, llc):
  35.         self.snep_server = SnepEchoServer(llc)
  36.         return llc
  37.        
  38.     def on_llcp_connect(self, llc):
  39.         self.snep_server.start()
  40.         return True
  41.  
  42. if __name__ == '__main__':
  43.     Main().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement