How to handle socketIO when app is not running

Sir

I've been doing alot of testing with socketIO and have got stuck with handling situations where my node app is simply offline. The documentation provides no real insight into this issue.

So if i run my website and node app is simply not running, console.log gives:

GET http://[url]:[port]/socket.io/socket.io.js

Uncaught ReferenceError: io is not defined

This is hardly surprising, how ever what i don't understand is how to handle these errors and simply have the script try to attempt a reconnect until it finally does reconnect (if ever).

My script looks like this:

<script src="http://[url]:[port]/socket.io/socket.io.js"></script>
<script>
  windows.onload = function()
  {
        socketio = io.connect("http://[url]:[port]");

        socketio.on('connecting', function() {
                 console.log('trying to connect');
        });             

        socketio.on('connect', function() {
                   console.log('connected');
        });     
  }
</script>

Is there a way to handle this kind of problem ?

SLaks

When the server is offline, your initial <script> tag to load the Socket.io client library fails, so you never get the io object in the first place.

To retry, you can add a new <script> tag to load the same URL again and see if it succeeds.

Better yet, copy the socket.io client library to the server hosting your HTML, so that the script will always load. You can then simply handle connection errors from io.connect().

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

How to handle code when app is killed by swiping in android?

来自分类Dev

IllegalArgumentException when running app. (Android)

来自分类Dev

How do I force SSL when running an express app behind Apache?

来自分类Dev

GCM BroadcastReceiver fired only when app is running or running at background

来自分类Dev

How to make an overlay when sharing into app in android?

来自分类Dev

How to make Bottle print stacktrace when running through apache modwsgi?

来自分类Dev

How to automatically switch focus to python console when running script in Pycharm?

来自分类Dev

How to get the source of a javascript bookmark from itself when running?

来自分类Dev

Detecting whether code is running in mirror when using Velocity to test a Meteor app

来自分类Dev

How to handle daylight saving when using the Outlook C# GetFreeBusy() API?

来自分类Dev

How to handle callback registration

来自分类Dev

How to handle encrypted string?

来自分类Dev

Google Cloud App Engine Flex Env上的Flask-Socketio服务器

来自分类Dev

在Windows Store App中从socketIO接收数据时添加UI元素

来自分类Dev

swift2 how to log when app is in background?

来自分类Dev

How does the app run on sencha touch when deployed on device?

来自分类Dev

How do I patch or modify a list inside of a function when running a unit test?

来自分类Dev

How to keep running a process in Android when disconnecting adb terminal? command "nohup" not found

来自分类Dev

When can I pass a function handle?

来自分类Dev

Matlab - How to check the existence of a handle

来自分类Dev

How to make keypress handle Enter

来自分类Dev

Bogus escape error when running regex

来自分类Dev

Problems running JerseyTest when dealing with HttpServletResponse

来自分类Dev

No ressources availbable when running unit test

来自分类Dev

Error when running emulator in Android Studio

来自分类Dev

AcceptSecurityContext fails when application is running as a service

来自分类Dev

When Int overflow cause IOS app crash, how can I remark it

来自分类Dev

How to set my activity properties to avoid interrupting other apps when my app comes in foreground

来自分类Dev

How to handle multiple configurations in VSTS Release management?

Related 相关文章

  1. 1

    How to handle code when app is killed by swiping in android?

  2. 2

    IllegalArgumentException when running app. (Android)

  3. 3

    How do I force SSL when running an express app behind Apache?

  4. 4

    GCM BroadcastReceiver fired only when app is running or running at background

  5. 5

    How to make an overlay when sharing into app in android?

  6. 6

    How to make Bottle print stacktrace when running through apache modwsgi?

  7. 7

    How to automatically switch focus to python console when running script in Pycharm?

  8. 8

    How to get the source of a javascript bookmark from itself when running?

  9. 9

    Detecting whether code is running in mirror when using Velocity to test a Meteor app

  10. 10

    How to handle daylight saving when using the Outlook C# GetFreeBusy() API?

  11. 11

    How to handle callback registration

  12. 12

    How to handle encrypted string?

  13. 13

    Google Cloud App Engine Flex Env上的Flask-Socketio服务器

  14. 14

    在Windows Store App中从socketIO接收数据时添加UI元素

  15. 15

    swift2 how to log when app is in background?

  16. 16

    How does the app run on sencha touch when deployed on device?

  17. 17

    How do I patch or modify a list inside of a function when running a unit test?

  18. 18

    How to keep running a process in Android when disconnecting adb terminal? command "nohup" not found

  19. 19

    When can I pass a function handle?

  20. 20

    Matlab - How to check the existence of a handle

  21. 21

    How to make keypress handle Enter

  22. 22

    Bogus escape error when running regex

  23. 23

    Problems running JerseyTest when dealing with HttpServletResponse

  24. 24

    No ressources availbable when running unit test

  25. 25

    Error when running emulator in Android Studio

  26. 26

    AcceptSecurityContext fails when application is running as a service

  27. 27

    When Int overflow cause IOS app crash, how can I remark it

  28. 28

    How to set my activity properties to avoid interrupting other apps when my app comes in foreground

  29. 29

    How to handle multiple configurations in VSTS Release management?

热门标签

归档