<s> '''<STR_LIT>''' <EOL> import sys <EOL> from twisted . internet . defer import Deferred <EOL> from twisted . internet . protocol import DatagramProtocol <EOL> from twisted . internet import reactor <EOL> from twisted . python import log <EOL> import txthings . coap as coap <EOL> import txthings . resource as resource <EOL> class Agent ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , protocol ) : <EOL> self . protocol = protocol <EOL> reactor . callLater ( <NUM_LIT:1> , self . requestResource ) <EOL> def requestResource ( self ) : <EOL> request = coap . Message ( code = coap . GET ) <EOL> request . opt . uri_path = ( '<STR_LIT>' , ) <EOL> request . opt . observe = <NUM_LIT:0> <EOL> request . remote = ( "<STR_LIT>" , coap . COAP_PORT ) <EOL> d = protocol . request ( request , observeCallback = self . printLaterResponse ) <EOL> d . addCallback ( self . printResponse ) <EOL> d . addErrback ( self . noResponse ) <EOL> def printResponse ( self , response ) : <EOL> print '<STR_LIT>' + response . payload <EOL> def printLaterResponse ( self , response ) : <EOL> print '<STR_LIT>' + response . payload <EOL> def noResponse ( self , failure ) : <EOL> print '<STR_LIT>' <EOL> print failure <EOL> log . startLogging ( sys . stdout ) <EOL> endpoint = resource . Endpoint ( None ) <EOL> protocol = coap . Coap ( endpoint ) <EOL> client = Agent ( protocol ) <EOL> reactor . listenUDP ( <NUM_LIT> , protocol ) <EOL> reactor . run ( ) </s>
