java net socketexception network is unreachable

Содержание

  1. Очередь просмотра
  2. Очередь
  3. YouTube Premium
  4. Хотите сохраните это видео?
  5. Пожаловаться на видео?
  6. Понравилось?
  7. Не понравилось?
  8. Текст видео
  9. 4 Answers 4
  10. Comments
  11. marbetschar commented Oct 18, 2016 •
  12. This comment has been minimized.
  13. marbetschar commented Oct 18, 2016 •
  14. This comment has been minimized.
  15. PranamBhat commented Jul 19, 2019

Очередь просмотра

Очередь

  • Удалить все
  • Отключить

YouTube Premium

Хотите сохраните это видео?

  • Пожаловаться

Пожаловаться на видео?

Выполните вход, чтобы сообщить о неприемлемом контенте.

Понравилось?

Не понравилось?

Текст видео

If you guys enjoy make sure to sub and like also share this video because a lot of people are have this problem.

Preferred DNS sever:208.67.222.222

Alternate DNS sever:208.67.220.220

This worked for me so hope it works for you also.

I am trying to download a xml text file from a web server using this method:

Sometimes this exception is thrown (where I specified is code):

Please guide me

4 Answers 4

You are facing a connection breakdown. Does this happen in 3G, WiFi or «plain» connection on a computer?

Anyway, you must assume that the connection may be lost from time to time, when writing your app. For example, with mobiles, this happens frequently in the tube, in basements, etc. With PC apps, this is less frequent but occurs sometimes.

A retry can be a good solution. And a clean error message that explains the network is not available at this moment too.

«Network is unreachable» means just that. You’re not connected to a network. It’s something outside of your program. Could be a bad OS setting, NIC, router, etc.

I faced situation of getting java.net.SocketException not sometimes but every time. I’ve added -Djava.net.preferIPv4Stack=true to java command line and my program started to work properly.

I haven’t tested with your code so it would be totally different case though, still I’d like to share my experience. (Also this must be too late answer though, I hope this answer still would help somebody in the future)

I recently faced similar experience like you such as some times Network is unreachable, but sometimes not. In short words, what was cause is too small time out. It seems Java throws IOException with stating «Network is unreachable» when the connection fails because of it. It was so misleading (I would expect something like saying «time out») and I spent almost a month to detect it.

Here I found another post about how to set time out. Alternative to java.net.URL for custom timeout setting

Again, this might not the same case as you got experienced, but somebody for the future.

Comments

Copy link Quote reply

marbetschar commented Oct 18, 2016 •

For some reason I receive the above error on the production machine (Linux). Strange thing is, on my dev machine — which is a windows system — there is no such error while using the exact same connection information.

Even more odd after several retries it just starts working, till the next time this code should be executed a few minutes later; then it needs again several retries to run properly.

Please note the code runs as a daemon within an endless loop, which sleeps several minutes between the different executions.

This comment has been minimized.

Copy link Quote reply

marbetschar commented Oct 18, 2016 •

Ok; it seems to be a regular networking issue. If I try to telnet autodiscover.domain.tld 443 I got the following errors on the Linux server:

I’ve also tried it on my Windows box; quite the same result. NO connection can be established with telnet . Now I’m curious: Why the hell does it work in Java on Windows without any error and on Linux at least after several tries? In my opinion it should either be a permanent failure or a permanent success . Does the EWS Java API switch to port 80 every once in a while?!

This comment has been minimized.

Copy link Quote reply

PranamBhat commented Jul 19, 2019

Whenever I run my application, I’m getting the connection request failure exception. The application tries to hit the URL and end up with connection failure.

I have tried the same on Postman. It is giving me 200: OK.

I have the proxy and port as well. How to use it in our spring boot application. Whenever the application runs it should take the respective proxy and port.

Источник: computermaker.info

Техника и Гаджеты
Добавить комментарий