java - SocketTimeoutException after four requests to local bitcoind -
i want connect bitcoind using java. plan use htmlunit , gson. right can complete single request successfully. however, can not more four subsequent requests due sockettimeoutexception being thrown @ fifth request.
i tried:
- waiting between requests. (no effect visible)
- forcing failing http status code e.g. requesting
getinfoo
instead ofgetinfo
. (i not timeout after 4 failing requests)
any or comment appreciated!
package test; import com.gargoylesoftware.htmlunit.browserversion; import com.gargoylesoftware.htmlunit.failinghttpstatuscodeexception; import com.gargoylesoftware.htmlunit.httpmethod; import com.gargoylesoftware.htmlunit.webclient; import com.gargoylesoftware.htmlunit.webrequest; import com.google.gson.gson; import java.io.ioexception; import java.net.sockettimeoutexception; import java.net.url; public class test { public static void main(string[] args) { webclient client = new webclient(browserversion.firefox_24); // http://[bitcoind-user]:[password]@localhost:[bitcoind-port] string baseurl = "http://admin:admin@localhost:8332/"; client.getoptions().settimeout(2000); while (true) { try { webrequest req = new webrequest(new url(baseurl)); req.setadditionalheader("content-type", "application/json"); req.sethttpmethod(httpmethod.post); jsonrequestbody body = new jsonrequestbody(); body.setmethod("getinfo"); req.setrequestbody(new gson().tojson(body, jsonrequestbody.class)); client.getpage(req); client.closeallwindows(); system.out.println("ok. (no exception)"); } catch (sockettimeoutexception tex) { system.out.println("not ok: sockettimeoutexception"); } catch (ioexception ex) { system.out.println("not ok: ioexception"); } catch (failinghttpstatuscodeexception hex) { system.out.println("not ok: failinghttpstatuscodeexception"); } } } }
(edit:)
removing .settimeout(2000)
did not well. measuring time each request shows quite quick:
ok. (no exception) timer: 1.161 seconds ok. (no exception) timer: 0.112 seconds ok. (no exception) timer: 0.115 seconds ok. (no exception) timer: 0.075 seconds not ok: sockettimeoutexception timer: 90.119 seconds not ok: sockettimeoutexception timer: 90.145 seconds not ok: sockettimeoutexception timer: 90.134 seconds
repeating same request multiple times in terminal using curl
took less 1 second bitcoind
should not causing problems.
firstly, try removing line:
client.getoptions().settimeout(2000);
if client takes 2 or more seconds process fifth request fail timeout exception.
secondly, make sure disable javascript if don't need it, can take more 2 seconds process too.
Comments
Post a Comment