Bitcoin Forum
May 13, 2024, 08:59:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoind : Java Client : Unexpected end of file from server Error  (Read 3950 times)
nakshathri (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
September 08, 2014, 11:09:17 AM
 #1

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
1715590798
Hero Member
*
Offline Offline

Posts: 1715590798

View Profile Personal Message (Offline)

Ignore
1715590798
Reply with quote  #2

1715590798
Report to moderator
The network tries to produce one block per 10 minutes. It does this by automatically adjusting how difficult it is to produce blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Newar
Legendary
*
Offline Offline

Activity: 1358
Merit: 1001


https://gliph.me/hUF


View Profile
September 08, 2014, 04:47:13 PM
 #2

This may be silly question, but do you also have server=1 in your conf?

OTC rating | GPG keyid 1DC91318EE785FDE | Gliph: lightning bicycle tree music | Mycelium, a swift & secure Bitcoin client for Android | LocalBitcoins
nakshathri (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
September 09, 2014, 03:43:08 AM
 #3

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
nakshathri (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
September 09, 2014, 05:48:36 AM
 #4

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
nakshathri (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
September 09, 2014, 06:08:19 AM
 #5

I added below entries to bitcoin.conf file. But still giving the same error:

rpcallowip=192.168.2.111
rpcallowip=127.0.0.1

virtualx
Hero Member
*****
Offline Offline

Activity: 672
Merit: 507


LOTEO


View Profile
September 09, 2014, 09:49:17 AM
 #6

I don't know what's wrong in this code, but there seem to be some working examples here:
https://github.com/cdelargy/BitcoinRPCClient/blob/master/src/main/java/com/cdelargy/bitcoin/RPCClient.java
http://bitcoin.stackexchange.com/questions/7529/how-to-communicate-between-java-and-bitcoind

Maybe it helps  Smiley

...loteo...
DIGITAL ERA LOTTERY


r

▄▄███████████▄▄
▄███████████████████▄
▄███████████████████████▄
▄██████████████████████████▄
▄██  ███████▌ ▐██████████████▄
▐██▌ ▐█▀  ▀█    ▐█▀   ▀██▀  ▀██▌
▐██  █▌ █▌ ██  ██▌ ██▌ █▌ █▌ ██▌
▐█▌ ▐█ ▐█ ▐█▌ ▐██  ▄▄▄██ ▐█ ▐██▌
▐█  ██▄  ▄██    █▄    ██▄  ▄███▌
▀████████████████████████████▀
▀██████████████████████████▀
▀███████████████████████▀
▀███████████████████▀
▀▀███████████▀▀
r

RPLAY NOWR
BE A MOON VISITOR!
[/center]
nakshathri (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
September 09, 2014, 10:27:37 AM
 #7

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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!