NetDog API Manual

2.1.0

Introduction

Welcome to the NetDog API users manual. The purpose of this manual is to document the C++ API function calls for NetDog. Please navigate to the classes tab to see the API information.

Example Program

Here is a framework example of a basic NetDog Client Application:

    int main(int argc, const char **argv) {
        char *serverAddr = "127.0.0.1";
        int serverPort = 6079;
        bool useEncryption = false;
        NDCore::SocketType stype = NDCore::UDP;

        NDGetOpt opts(argc, argv, "ts:p:e");
        for(uint32_t i = 0;i < opts.getNumOpts();i ++){
            switch(opts.getOpt(i)){
                case 't':
                    stype = NDCore::TCP;
                    break;
                case 's':
                    serverAddr = opts.getArg(i);
                    break;
                case 'p':
                    serverPort = atoi(opts.getArg(i));
                    break;
                case 'e':
                    useEncryption = true;
                    break;

                default:
                    usage();
            }
        }

       // initialize core
       NDCore* core = new NDCore();

       // Create Address object of our server
       NDSocketAddress *addr = core->createSocketAddress();
       addr->setAddress(serverAddr);
       addr->setPort(serverPort);

       // create a channel
       NDChannel *channel = NULL;
       if(core->createChannel(stype, 0, &channel) != NDRES_OK){
          printf("Failed to create channel!\n");
          return 1;
       }

        // Encryption?
        const char *serverKey = NULL;
        if(useEncryption){
            serverKey = "srv.pub";
            channel->generateLocalKeys(1024);
        }

       // Connect to the server
       printf("Connecting to server at Addr[%s] Port[%d]\n", serverAddr, serverPort);
       NDConn *conn = NULL;
       if (channel->loginToHost(stype, addr, "username", "password", &conn, serverKey) != NDRES_OK){
          printf("Failed to connect to remote host!\n");
          return 1;
       }
        printf("Connected to node_id %llu\n", (long long unsigned)conn->getRemoteIdentity().getNodeID());
        printf("We were assigned node_id %llu\n", (long long unsigned)channel->getLocalIdentity().getNodeID());

        // Do Something


        ...


        // Shut down
       delete core;
       printf("done\n");
       return 0;

    }

    

Generated on Wed Jul 21 18:14:48 2010 for nd2 by  doxygen 1.6.1