Sorry guys, I am at Day 1 using this platform, and I can’t seem to get by the first basic steps! lcb_connect is calling the error handler with “Could not connect to server within allotted time”. Below is the code. I get LCB_SUCCESS as the immediate return from the connect call (the error is detected in the error handler).
I have verified firewall allows connection (and I telnet’d in, and if I hit enter or type anything, it says “ERROR”). Obviously, I blanked out the pwd. I was not sure what to use as the user since that was not specified when the bucket was created, only the password.
I am a little lost – thought this was going to be a one-day integration!!!
Thanks,
Bret
#include <stdio.h>
#include "libcouchbase/couchbase.h"
#define CHECK(t,e) printf("%s; %s\n",t, (e==LCB_SUCCESS?"Pass":"Fail"));
static enum {
CB_CONNECT = 1,
CB_GET,
CB_ERROR = 999,
CB_NONE
};
int STATE = 0;
void cb_config (lcb_t cbi, lcb_configuration_t cbconfig) {
printf ("Config Callback: ");
switch (cbconfig) {
case LCB_CONFIGURATION_NEW: printf ("NEW"); break;
case LCB_CONFIGURATION_CHANGED: printf ("CHANGED"); break;
case LCB_CONFIGURATION_UNCHANGED: printf ("UNCHANGED"); break;
default: printf ("OTHER"); break;
}
printf ("\n");
}
void cb_get (lcb_t cbi, const void * cookie, lcb_error_t cberr, const lcb_get_resp_t * rsp) {
STATE = (cberr==LCB_SUCCESS ? STATE : CB_ERROR);
}
void cb_error (lcb_t cbi, lcb_error_t cberr, const char * message) {
STATE = (cberr==LCB_SUCCESS ? STATE : CB_ERROR);
}
int main (int argc, char ** argv) {
// init the couchbase lib
lcb_t cbi;
struct lcb_create_st cbopts;
memset (&cbopts, 0, sizeof(cbopts));
cbopts.version = 1;
cbopts.v.v1.host = "levycodev.com:11211";
cbopts.v.v1.bucket = "DNP";
cbopts.v.v1.user = "DNP";
cbopts.v.v1.passwd = "*********";
cbopts.v.v1.type = LCB_TYPE_BUCKET;
lcb_error_t cberr = lcb_create (&cbi, &cbopts);
CHECK ("LCB:Create", cberr);
// configure handlers
lcb_set_configuration_callback (cbi, cb_config);
lcb_set_error_callback (cbi, cb_error);
lcb_set_get_callback (cbi, cb_get);
// connect to the cluster/instance
STATE = CB_CONNECT;
cberr = lcb_connect (cbi);
CHECK ("LCB:Connect", cberr);
lcb_wait(cbi);
CHECK ("LCB:Connect; after wait", STATE);
// read the test document
STATE = CB_GET;
lcb_get_cmd_t * cmd = (lcb_get_cmd_t*) calloc(1,sizeof(lcb_get_cmd_t));
cmd->version = 0;
cmd->v.v0.key = "this-is-a-test";
cmd->v.v0.nkey = strlen((const char *)cmd->v.v0.key);
lcb_get_cmd_st * cmds[] = { cmd };
cberr = lcb_get (cbi, "test", 1, cmds);
CHECK ("LCB:Get", cberr);
lcb_wait(cbi);
CHECK ("LCB:Get; after wait", STATE);
// tests done
return (0);
}