<s> import getopt <EOL> import sys <EOL> from coapthon . resources . resource import Resource <EOL> from coapthon . server . coap import CoAP <EOL> from exampleresources import BasicResource , Long , Separate , Storage , Big , voidResource , XMLResource , ETAGResource , Child , MultipleEncodingResource <EOL> __author__ = '<STR_LIT>' <EOL> class CoAPServer ( CoAP ) : <EOL> def __init__ ( self , host , port , multicast = False ) : <EOL> CoAP . __init__ ( self , ( host , port ) , multicast ) <EOL> self . add_resource ( '<STR_LIT>' , BasicResource ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , Storage ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , Separate ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , Long ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , Big ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , voidResource ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , XMLResource ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , MultipleEncodingResource ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , ETAGResource ( ) ) <EOL> self . add_resource ( '<STR_LIT>' , Child ( ) ) <EOL> print "<STR_LIT>" + host + "<STR_LIT::>" + str ( port ) <EOL> print self . root . dump ( ) <EOL> def usage ( ) : <EOL> print "<STR_LIT>" <EOL> def main ( argv ) : <EOL> ip = "<STR_LIT:127.0.0.1>" <EOL> port = <NUM_LIT> <EOL> try : <EOL> opts , args = getopt . getopt ( argv , "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except getopt . GetoptError : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> for opt , arg in opts : <EOL> if opt == '<STR_LIT>' : <EOL> usage ( ) <EOL> sys . exit ( ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> ip = arg <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> port = int ( arg ) <EOL> server = CoAPServer ( ip , port ) <EOL> try : <EOL> server . listen ( <NUM_LIT:10> ) <EOL> except KeyboardInterrupt : <EOL> print "<STR_LIT>" <EOL> server . close ( ) <EOL> print "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv [ <NUM_LIT:1> : ] ) </s>
