Hi Ben, Thanks for your update on the R client implementation. Finally some feedback (but maybe you’ve already solved your problem?):
> My question for this moment is, if the response '0a' in testSock is > truly the response from the basexserver or is this an error that is > returned by the socket? > > Is the a list that explains the errorcodes returnde by the basex-server? As I didn’t have a chance to run your code, I can only guess what might have gone wrong. In every case, 0A is no error code, so I would I assume it’s part of a result that hasn’t been retrieved in its full length. It could be the last newline character of your first result. Errors will always be indicated by a trailing 01 byte [1]. In the following example, the server returns "1" as result, the info string "OK" and the success code "0": 31 00 // UTF8 result string '1', followed by 00 suffix 4F 4B 00 // UTF8 info string 'OK', followed by 00 suffix 00 // success code If an error occurs, 01 instead of 00 will be sent as last byte, and the info string that you have received in the previous bytes contains the error message. Hope this helps, Christian [1] http://docs.basex.org/wiki/Server_Protocol#Command_Protocol On Wed, Apr 4, 2018 at 4:57 PM, Ben Engbers <ben.engb...@be-logical.nl> wrote: > Hi, > > Since a few weeks I am working on a client for the R language. I use > BaseXClient.java as example. And in R I use the R6 package for object > orientation. > > And at this moment I can login and issue COMMANDs. > > I guess that at this moment and for this question, these parts of the > code are the most essential: > > - socket-definition: > private$sock <- socketConnection(host = "localhost", port = 1984L, > open = "w+b", server = FALSE, blocking = TRUE, encoding = "utf-8") > > - execute a command: > execute = function(command) { > flush(private$sock) > private$send(command) > private$info <- private$receive() > private$testSock() > result <- private$show_receive() > return(result) > } > > - get the server-response: > receive = function(input, output) { > private$info <- NULL > if (missing(input) || missing(output)) { > output <- raw(0) > output <- private$receive(private$sock, output) > return(rawToChar(output)) > } else { > while((rd <- readBin(input, what = "raw", n =1)) >0) { > if (rd == 0xff) next > output <- append(output, rd) > } > return(output) > } > > - test the result (Exceptionhandling): > testSock = function() { > tryCatch({ > test <- readBin(private$sock, what = "raw", n =1) > }, error = function(e) { > print("ERROR") > print(e) > return(FALSE) > }) > return(test == 0x00) > } > > > I create a session and issue some commands from in a script: > Session <- BasexClient$new("localhost", 1984, "admin", "admin") > print(Session$execute("xquery 1 to 5")) > print(Session$execute("xquery 6 to 10")) > print(Session$execute("list")) > > When testsock is used in the first call, the readBin in the third line > returns 00! Perfect! Result is > [[1]] > [1] "1" "2" "3" "4" "5" > When testsock is used for the second call returns 0a ;-( and output is [[1]] > character(0) > > When I comment out the first two calls, result is: > [[1]] > [1] "Name Resources Size Input Path > " > [2] > "---------------------------------------------------------------------------------------------------------------" > > [3] "EUR 164 12288704 /home/bengbers/Programs/basex/ > " > [4] "EUR_Debat 1492 44857696 > /home/bengbers/DataScience/TextMining-Web-Analytics/Text-mining > case/xml_files/ " > [5] "test1 0 4568 > " > [6] "" > > [7] "3 database(s)." > > > My question for this moment is, if the response '0a' in testSock is > truly the response from the basexserver or is this an error that is > returned by the socket? > > Is the a list that explains the errorcodes returnde by the basex-server? > > Ben