Exemple #1
0
int main(int argc, char **argv)
{
    ember_opt options;
    ember_opt_init(&options, sizeof(options));
	// Octal junk is telnet-ese for forcing character mode
	// http://stackoverflow.com/questions/273261/force-telnet-client-into-character-mode
    //options.greeting   = "\377\375\042\377\373\001Welcome to the ember example\n";
	options.greeting   = "Welcome to the ember example\n";
    options.prompt     = "emb> ";
    options.listenPort = 10000;
	options.errorFn    = Error;

    ember_ctx ctx = ember_init(&options);
    ember_add_command(ctx, "Hello", Hello, NULL, "Print the standard greeting");
    ember_add_command(ctx, "Broadcast", Broadcast, "<s/text>", "Send a message to all connected terminals");
    ember_add_command(ctx, "Quit", Quit, NULL, "Quit the example program");

    ember_err err = ember_start(ctx);
    if(err != EMBER_OK) {
        char buf[1024];
        err = ember_last_error(ctx, buf, sizeof(buf));
        printf("Error %d: %s\n", err, buf);
        return err;
    }

    while(!s_done) {
        // Wait one second for events
        ember_poll(ctx, 1000);
        
    }

    ember_destroy(ctx);
}
void runProvider(int argc, char **argv)
{
   int port;

   ember_init(onThrowError, onFailAssertion, malloc, free);
   initializePpmStreams();
   buildTree(&_root);

   if(argc >= 2)
   {
      port = atoi(argv[1]);

      printf_s("accepting client on port %d\n", port);
      acceptClient(port);
   }

   sampleNode_free(&_root);
   freePpmStreams();
}