1

I want to achieve the basic task of connection to a neo4j database using C++.
For this, I got libneo4j-client and copied the code from https://neo4j-client.net/. Compilation works fine.

Now I executed the following code:

neo4j_client_init();

neo4j_connection_t* connection = neo4j_connect("neo4j://user:pass@localhost:7687", NULL, NEO4J_INSECURE);
assert(connection);

This results in the assert stopping the execution as the connection is NULL.
Note that of course I entered an actual user name and password.

I made sure that the server actually exists. Opening localhost:7474 in the browser opens the browser interface that is to expect, accepts the user name and password and mentions that 7687 is a valid port.
Likewise, accessing the database using cypher-shell also works fine.

As far as I see it, neo4j://localhost:7687 should be the correct address.

I tried out several variations of this, like omitting the neo4j:// protocol identifier, trying to replace it with bolt, http and https identifiers, trying out 7474 as port, all combinations of this.

Then I tried to get some diagnostic data, using the logging capabilities of the library:

FILE* log_file = fopen("log.dat" , "w");
neo4j_logger_provider* logger = neo4j_std_logger_provider(log_file, 1, 0);
neo4j_config_t* config = neo4j_new_config();
neo4j_config_set_username(config, "username");
neo4j_config_set_password(config, "password");
neo4j_config_set_logger_provider(config, logger);

neo4j_connection_t* connection = neo4j_connect("neo4j://localhost:7687", config, NEO4J_INSECURE);
assert(connection);

As a result of calling fopen, log.dat is created, but that's it, file is empty afterwards, assertion fails.

At this point, I don't know what else to try or how to do any sort of diagnosis. Again, my goal is to connect with the database in general, I am not bound to libneo4j-client in particular. However, I want to write a program that can work on a new system without further installations, thus I can't use system() to call something like cyper-shell that would have to be installed. Plus later, there will be a lot of data flow, so I want the connection to be as direct as possible. Anybody wiser than me?

One thing that I am not sure are version compatibilities of libneo4j-client and the version of the database.
I also found the four year old question Using Neo4j database from C++ and I will start reading into the cyper API, but I hope somewhat that it will work out with libneo4j-client.
Edit: According to https://neo4j.com/developer/c/, libneo4j-client is in fact the default meant to be used by C++, and there are not any alternatives listed.

Edit: neo4j-client itself seems also not to work:

$ neo4j-client -u neo4j localhost
error: A secure connection could not be esablished (try --insecure)
$ neo4j-client -u neo4j localhost --insecure
error: Could not agree on a protocol version
$ neo4j-client -u neo4j neo4j://localhost:7687
error: A secure connection could not be esablished (try --insecure)
$ neo4j-client -u neo4j neo4j://localhost:7687 --insecure
error: Could not agree on a protocol version

Does this signify an incompatibility? The protocol that neo4j-client using being not that the server uses?

In Connection with neo4j-client failed on OS X yosemite, this was solved by changing the port, however, so not sure about this either.

Aziuth
  • 3,652
  • 3
  • 18
  • 36
  • I have the impression that your client's version is not supported (not compatible) by your server. It must either be too recent or too old. is there a Windows version of this library ? – Landstalker Mar 05 '20 at 13:47
  • @Landstalker The release section https://github.com/cleishm/libneo4j-client/releases does not mention windows. The github for the source code https://github.com/cleishm/libneo4j-client only states that it worked on linux and mac so far, but that doesn't mean one can't compile it under windows. The library itself should be able to being build without any dependencies. – Aziuth Mar 05 '20 at 13:55

1 Answers1

1

The problem was solved by downgrading the version of Neo4J.

Version 4.0.1 uses a higher version of the bolt protocol, which isn't documented so far, and thus not used by neo4j-client.
Version 3.5 uses the old protocol (bolt version 1) and is thus compatible.

Aziuth
  • 3,652
  • 3
  • 18
  • 36