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