コード例 #1
0
ファイル: main-server.c プロジェクト: errordeveloper/smcp
int
main(int argc, char * argv[]) {
	smcp_t smcp = smcp_create(0);
	struct plugtest_server_s plugtest_server = {};
	struct smcp_node_s root_node = {};

	// Set up the root node.
	smcp_node_init(&root_node,NULL,NULL);

	// Set up the node router.
	smcp_set_default_request_handler(smcp, &smcp_node_router_handler, &root_node);

#if DEBUG
	fprintf(stderr,"DEBUG = %d\n",DEBUG);
#endif
#if VERBOSE_DEBUG
	fprintf(stderr,"VERBOSE_DEBUG = %d\n",VERBOSE_DEBUG);
#endif
	fprintf(stderr,"SMCP_EMBEDDED = %d\n",SMCP_EMBEDDED);
	fprintf(stderr,"SMCP_USE_BSD_SOCKETS = %d\n",SMCP_USE_BSD_SOCKETS);
	fprintf(stderr,"SMCP_DEFAULT_PORT = %d\n",SMCP_DEFAULT_PORT);
	fprintf(stderr,"SMCP_MAX_PATH_LENGTH = %d\n",SMCP_MAX_PATH_LENGTH);
	fprintf(stderr,"SMCP_MAX_URI_LENGTH = %d\n",SMCP_MAX_URI_LENGTH);
	fprintf(stderr,"SMCP_MAX_PACKET_LENGTH = %d\n",(int)SMCP_MAX_PACKET_LENGTH);
	fprintf(stderr,"SMCP_MAX_CONTENT_LENGTH = %d\n",SMCP_MAX_CONTENT_LENGTH);
	fprintf(stderr,"SMCP_USE_CASCADE_COUNT = %d\n",SMCP_USE_CASCADE_COUNT);
	fprintf(stderr,"SMCP_MAX_CASCADE_COUNT = %d\n",SMCP_MAX_CASCADE_COUNT);
	fprintf(stderr,"SMCP_ADD_NEWLINES_TO_LIST_OUTPUT = %d\n",SMCP_ADD_NEWLINES_TO_LIST_OUTPUT);
	fprintf(stderr,"SMCP_AVOID_PRINTF = %d\n",SMCP_AVOID_PRINTF);
	fprintf(stderr,"SMCP_AVOID_MALLOC = %d\n",SMCP_AVOID_MALLOC);
	fprintf(stderr,"SMCP_CONF_USE_DNS = %d\n",SMCP_CONF_USE_DNS);
	fprintf(stderr,"SMCP_CONF_MAX_TRANSACTIONS = %d\n",SMCP_CONF_MAX_TRANSACTIONS);
	fprintf(stderr,"SMCP_CONF_MAX_ALLOCED_NODES = %d\n",SMCP_CONF_MAX_ALLOCED_NODES);
	fprintf(stderr,"SMCP_CONF_MAX_TIMEOUT = %d\n",SMCP_CONF_MAX_TIMEOUT);
	fprintf(stderr,"SMCP_CONF_DUPE_BUFFER_SIZE = %d\n",SMCP_CONF_DUPE_BUFFER_SIZE);
	fprintf(stderr,"SMCP_OBSERVATION_KEEPALIVE_INTERVAL = %d\n",SMCP_OBSERVATION_KEEPALIVE_INTERVAL);
	fprintf(stderr,"SMCP_OBSERVATION_DEFAULT_MAX_AGE = %d\n",SMCP_OBSERVATION_DEFAULT_MAX_AGE);
	fprintf(stderr,"SMCP_VARIABLE_MAX_VALUE_LENGTH = %d\n",SMCP_VARIABLE_MAX_VALUE_LENGTH);
	fprintf(stderr,"SMCP_VARIABLE_MAX_KEY_LENGTH = %d\n",SMCP_VARIABLE_MAX_KEY_LENGTH);
#ifdef SMCP_DEBUG_OUTBOUND_DROP_PERCENT
	fprintf(stderr,"SMCP_DEBUG_OUTBOUND_DROP_PERCENT = %.1f%%\n",SMCP_DEBUG_OUTBOUND_DROP_PERCENT*100.0);
#endif
#ifdef SMCP_DEBUG_INBOUND_DROP_PERCENT
	fprintf(stderr,"SMCP_DEBUG_INBOUND_DROP_PERCENT = %.1f%%\n",SMCP_DEBUG_INBOUND_DROP_PERCENT*100.0);
#endif


	plugtest_server_init(&plugtest_server,&root_node);

	fprintf(stderr,"\nPlugtest server listening on port %d.\n", smcp_get_port(smcp));

	while(1)
		smcp_process(smcp,30*MSEC_PER_SEC);

	return 0;
}
コード例 #2
0
ファイル: example-1.c プロジェクト: paulobrizolara/smcp
int
main(void)
{
	smcp_t instance;

	SMCP_LIBRARY_VERSION_CHECK();

	// Create our instance on the default CoAP port. If the port
	// is already in use, we will pick the next available port number.
	instance = smcp_create();

	if (!instance) {
		perror("Unable to create SMCP instance");
		exit(EXIT_FAILURE);
	}

	smcp_plat_bind_to_port(instance, SMCP_SESSION_TYPE_UDP, COAP_DEFAULT_PORT);

	printf("Listening on port %d\n",smcp_plat_get_port(instance));

	// SMCP will always respond to requests with METHOD_NOT_IMPLEMENTED
	// unless a request handler is set. Unless your program is only
	// making CoAP requests, you'll need a line like the following
	// in your program. The request handler may either handle the
	// request itself or route the request to the appropriate handler.
	smcp_set_default_request_handler(instance, &request_handler, NULL);

	// Loop forever. This is the most simple kind of main loop you
	// can haave with SMCP. It is appropriate for simple CoAP servers
	// and clients which do not need asynchronous I/O.
	while (1) {
		smcp_plat_wait(instance, CMS_DISTANT_FUTURE);
		smcp_plat_process(instance);
	}

	// We won't actually get to this line with the above loop, but it
	// is always a good idea to clean up when you are done. If you
	// provide a way to gracefully exit from your own main loop, you
	// can tear down the SMCP instance using the following command.
	smcp_release(instance);

	return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: example-2.c プロジェクト: errordeveloper/smcp
int
main(void) {
	smcp_t instance = smcp_create(0);

	if(!instance) {
		perror("Unable to create SMCP instance");
		abort();
	}

	printf("Listening on port %d\n",smcp_get_port(instance));

	smcp_set_default_request_handler(instance, &request_handler, NULL);

	while(1) {
		smcp_process(instance, CMS_DISTANT_FUTURE);
	}

	smcp_release(instance);

	return 0;
}