Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Socket connection offline vs busy

Socket connection offline vs busy

Scheduled Pinned Locked Moved Java
visual-studiosysadminhelpquestion
9 Posts 3 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohnCodding
    wrote on last edited by
    #1

    Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?

    L E 3 Replies Last reply
    0
    • J JohnCodding

      Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      As far as I recall if the server is offline then your code will receive an exception indicating that a connection was refused. If the server is busy the underlying protocol will retry. But you should check the various socket errors that may occur, e.g. the Windows set: Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docs[^].

      J 1 Reply Last reply
      0
      • L Lost User

        As far as I recall if the server is offline then your code will receive an exception indicating that a connection was refused. If the server is busy the underlying protocol will retry. But you should check the various socket errors that may occur, e.g. the Windows set: Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docs[^].

        J Offline
        J Offline
        JohnCodding
        wrote on last edited by
        #3

        Aren't those C++ errors? I was asking for Java socket.

        L 2 Replies Last reply
        0
        • J JohnCodding

          Aren't those C++ errors? I was asking for Java socket.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, but they are based on actual sockets which are the same for all languages. I could not find a definitive list for Java, you should check the Java documentation.

          1 Reply Last reply
          0
          • J JohnCodding

            Aren't those C++ errors? I was asking for Java socket.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The best I could find is SocketTimeoutException (Java Platform SE 7 )[^]

            J 1 Reply Last reply
            0
            • L Lost User

              The best I could find is SocketTimeoutException (Java Platform SE 7 )[^]

              J Offline
              J Offline
              JohnCodding
              wrote on last edited by
              #6

              I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.

              L 1 Reply Last reply
              0
              • J JohnCodding

                I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Did the exceptions include any message text to explain what was the underlying cause? When I run my Java client against an offline server I get:

                Exception in thread "main" java.net.ConnectException: Connection refused: connect

                There may be some more useful information at Java Network Programming FAQ[^].

                1 Reply Last reply
                0
                • J JohnCodding

                  Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Ping the server; if you get a response, the server is online. "Connecting" is another matter. [https://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability\](https://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability)

                  "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                  1 Reply Last reply
                  0
                  • J JohnCodding

                    Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?

                    E Offline
                    E Offline
                    englebart
                    wrote on last edited by
                    #9

                    Check inetaddress.isReachable. It is similar to ping

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups