手机sockettimeout怎么解决
Android\u771f\u673a\u8c03\u8bd5\uff1ajava.net.SocketTimeoutException\u8fde\u63a5\u8d85\u65f6\uff0c\u5982\u679c\u670d\u52a1\u5668\u4e5f\u662f\u672c\u673a\u7684\u8bdd\uff0cip\u5730\u5740\u8981\u5199\u4e3a10.0.2.2
\u8fd9\u4e2a\u95ee\u9898\u4e00\u822c\u662f\u7aef\u53e3\u672a\u6253\u5f00 \u68c0\u67e5\u4e00\u4e0b 80\u7aef\u53e3\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u901a\u8baf
出现这种问题的原因是读取文件超时,解决方法是将HTTP Keep-Alive Timeout这个参数设置地尽量大,但是有没有更好的解决方法,由于使用的服务器是tomcat,便可以通过修改服务器配置来解决该问题,具体的解决方法如下:修改tomcat配置文件server.xml,找到类似于下面配置:
1234 <Connector port="8086" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" />
将上面的参数disableUploadTimeout值改为false即可。
网络连接超时,试着ping一下服务器,记得用局域网内的别的主机ping。
如果ping不同说明是防火墙拦住了,把ipv4规则打开!
绛旓細java.net.SocketTimeoutException: read is alrady timed out 琛ㄧず璇诲彇瓒呮椂 缁欎釜绀轰緥 socket.setSoTimeout(1000); // 杩欓噷鏄1绉掞紝鏈濂藉厛涓嶈缃 InputStream is = socket.getInputStream();is.read();绗竴琛岃缃簡涓涓秴鏃舵椂闂达紝杩欎釜鏃堕棿鏃舵墽琛宨s.read()鐨勮秴鏃舵椂闂 璇锋鏌ヤ笅锛屼綘鏄惁灏嗚繖涓椂闂...
绛旓細瀛楅潰鎰忔 杩炴帴瓒呮椂 鐪嬩笅鏄惁缃戠粶 涓嶉 绔彛鏄惁涓鏍 鏄笉鏄闃茬伀澧欏惂绔彛灞忚斀浜
绛旓細package socket;import java.io.ByteArrayOutputStream;import java.io.InputStream;import java.net.InetSocketAddress;import java.net.ServerSocket;import java.net.Socket;import java.net.SocketAddress;import java.net.SocketException;import java.net.SocketTimeoutException;import java.text.SimpleDate...
绛旓細鍏蜂綋鐨勮В鍐虫柟娉曞涓嬶細淇敼tomcat閰嶇疆鏂囦欢server.xml锛屾壘鍒扮被浼间簬涓嬮潰閰嶇疆:<Connector port="8086" maxHttpHeaderSize="8192"銆俶axThreads="150" minSpareThreads="25" maxSpareThreads="75"銆俥nableLookups="false" redirectPort="8443" acceptCount="100"銆俢onnectionTimeout="20000" disableUploadTimeout="true...
绛旓細private int timeoutSocket = 2000;httpParameters = new BasicHttpParams();// Set the timeout in milliseconds until a connection is established.HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);// Set the default socket timeout (SO_TIMEOUT)// in milliseconds ...
绛旓細瀹氫箟鏂规硶 private loadData() throws SocketTimeoutException { ...} loadData鏂规硶鍙兘鎶涘嚭SocketTimeoutException寮傚父鍑烘潵锛岄偅涔堝湪璋冪敤loadData鏂规硶鐨勬椂鍊欏氨闇濂藉噯澶 渚嬪锛歵ry { proDialog = ProgressDialog.show(Main.this, "", "姝e湪鍔犺浇鏁版嵁...");loadDate(page);} catch (SocketTimeoutException...
绛旓細鏈夋椂浣跨敤httpclient鐨勬椂鍊欙紝闇瑕佺瓑寰匩闀挎椂闂达紝鍙兘姝ゆ椂浣犲喅瀹氭斁寮冩垨鑰呴噸璇曘傚疄鐜颁笂闈炲父绠鍗曟坊鍔犱竴涓弬鏁板嵆鍙 /杩欓噷鐨勮秴鏃跺崟浣嶆槸姣銆傝繖閲岀殑http.socket.timeout鐩稿綋浜嶴O_TIMEOUT httpClient.getParams().setIntParameter("http.socket.timeout",3000);HttpConnectionManagerParams managerParams = httpClient....
绛旓細绗竴涓猚atch鐨勫紓甯稿簲璇ユ敼涓SocketTimeoutException
绛旓細杩欎釜socket涓鑸粯璁ゅ氨鏄渶闀裤傚彲浠ュ皾璇曠敤nio杩涜璇诲啓~~~
绛旓細// 鏍规嵁鍐呭鏉ユ簮鍦板潃鍒涘缓涓涓狧ttp璇锋眰 HttpPost request = new HttpPost(SERVER_URL);//璁剧疆璇锋眰瓒呮椂 int timeoutConnection = 3 * 1000;HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);//璁剧疆鍝嶅簲瓒呮椂 int timeoutSocket = 5 * 1000;HttpConnectionParams.setSoTimeout(...