android - Second HttpUrlConnection hangs on real device -


i'm using basic-http-client in longpolling library signala. basic-http-client based on httpurlconnection. when running in emulator possible have 1 longrunning post-request open , simultaneous post-request. when running code on real device second post hanging until first has completed. it's hanging on getresponsecode function.

whats difference between running in emulator or on real device? how can enable multiple , simultaneous request?

quoting solution similar question asked here :-

the connection pool used httpurlconnection when keeping connections alive broken such tries use connections have been closed server. default android sets keepalive on connections.

system.setproperty("http.keepalive", "false"); workaround disables keepalive connections avoid bug in connection pool.

conn.setrequestproperty("connection","keep-alive"); turns keepalive on particular connection, reversing system.setproperty("http.keepalive", "false"); does.

also explicitly call connect() makes clear ending connection setup. i'm not sure if calling method optional or not.

system.setproperty("http.keepalive", "false"); httpurlconnection conn = (httpurlconnection) murl.openconnection(); conn.setusecaches(false);  conn.setrequestproperty("user-agent", useragent); conn.setconnecttimeout(30000); conn.setdooutput(true);  conn.setdoinput(true);  consumer.sign(conn);  conn.connect();  inputsource = new inputsource(conn.getinputstream()); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -