필터 지우기
필터 지우기

How to reiterate the function automatically if my code stops working because my internet disconnected

조회 수: 1 (최근 30일)
Hello,
I want to get weather data from a URL given below:
xdom = xmlread('http://api.openweathermap.org/data/2.5/forecast? q=Texel,NL&mode=xml&APPID=f3e1e8697d3d20e5d91f193ef02e4846')
Now my whole code is running properly, but due to bad internet connection my code stopped. To safeguard my whole code that it doesn't happen again, I want to develop a code which will help in reiterating the code after every 30 seconds until the internet connection is restored. Can someone help me with the same.

채택된 답변

Jan
Jan 2015년 4월 14일
How does this code stop? With an error message? Then TRY-CATCH is a direct solution:
success = false;
while ~success
try
xdom = xmlread('...');
success = true;
catch ME
disp('Failed:');
disp(ME.message);
pause(30);
end
end
  댓글 수: 1
Punit Gandhi
Punit Gandhi 2015년 4월 15일
Hey Jan,
Thanks for the code. It works perfectly. It shows me this error when internet connection is not working.
>> isnet Failed: Java exception occurred: java.net.UnknownHostException: api.openweathermap.org
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Web Services from MATLAB Using HTTP에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by