Author

Topic: Bitcoind : Java Client : Unexpected end of file from server Error (Read 3972 times)

newbie
Activity: 5
Merit: 0
Thank you. But after all the tweaking, i am able to get it working properly. For the benefit of others, here is the Java Code for making JSON-RPC calls to bitcoind (Using Jersey Client):

bitcoin.conf entries :

rpcuser=bitcoinrpc
rpcpassword=5UKQTzWTf7EEJnkShZhr9tbjpDVNmLMgQkFfWsnZhLey   
testnet=1
server=1
#txindex=1
rpcallowip=192.168.2.*
rpcallowip=127.0.0.1
rpcport=8999
#rpctimeout=60000


Make sure you change the port number and dont forget to provide rpcallowip entry pointing to respective IP address.

Client Code:

DefaultClientConfig config = new DefaultClientConfig();

config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
            Boolean.TRUE);
Client client = Client.create(config);
client.addFilter(new HTTPBasicAuthFilter(username, password));
WebResource webResource = client.resource(url);
String input = "{\"id\":\"jsonrpc\",\"method\":\"listaccounts\",\"params\":[]}";
ClientResponse response = webResource.accept("application/json").type("application/json")
           .post(ClientResponse.class, input);


Thats it. Your good to start with bitcoind integration.

Regards,
Manjunath
newbie
Activity: 5
Merit: 0
I added below entries to bitcoin.conf file. But still giving the same error:

rpcallowip=192.168.2.111
rpcallowip=127.0.0.1

newbie
Activity: 5
Merit: 0
When I inspect the request and response, its giving "Remote server closed the connection before sending response header" error as part of HTTP failure scenario. Following is the request data content :

URL : http://192.168.2.111:18333/

Request Data:

{
   "method": "getblockcount",
   "params": [],
   "id": "1"
}

Please help me in understanding where the mistake is.

Regards,
Manjunath
newbie
Activity: 5
Merit: 0
Yes, i do have that configuration set. And also i am starting the server with following option:

bitcoind -server -listen

Let me know if you need any further details.

Regards,
Manjunath
legendary
Activity: 1358
Merit: 1001
https://gliph.me/hUF
This may be silly question, but do you also have server=1 in your conf?
newbie
Activity: 5
Merit: 0
Hello All,

I am very new to bitcoin and this is my first experiment with bitcoind.

We have been trying to develop an Java based application on BTC using bitcoind. We are using simple HTTP Post using Jersey client with basic authentication like given below.


Client client = Client.create();

String url = "http://"+username+':'+password+"@localhost:18333";
//String url = "http://localhost:18333";
System.out.println("URL is : "+url);
WebResource webResource = client.resource(url);

Authenticator.setDefault(new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
   return new PasswordAuthentication (username, password.toCharArray());
    }
    });

String input = "{\"method\":\"getblockcount\",\"params\":[],\"id\":\"1\"}";
ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);


When we execute this, we are getting

Caused by: java.net.SocketException: Unexpected end of file from server
   at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:772)
   at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
   at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:769)


From the exception what I understand is, there are some server side errors but i am not able to see errors in the log files.

The entries in the bitcoin.conf file is as follows:

rpcuser=bitcoinrpc
rpcpassword=5UKQTzWTf7EEJnkShZhr9tbjpDVNmLMgQkFfWsnZhLey
testnet=1

Really appreciate any help in resolving this error.  Thank you in advance.

regards,
Manjunath
Jump to: