Node.js socket.io-client connect_failed / connect_error event

后端 未结 4 2031
难免孤独
难免孤独 2020-12-05 07:40

I am playing around with node.js and socket.io-client. I am trying to connect to a channel that does not exist in order to trigger the event \'connect_failed\' (as specified

4条回答
  •  自闭症患者
    2020-12-05 08:29

    From the documentation:

    connect_failed

    Fired when the connection timeout occurs after the last connection attempt. This only fires if the connectTimeout option is set. If the tryTransportsOnConnectTimeout option is set, this only fires once all possible transports have been tried.

    So this event fires only if the connectTimeout option is set (the implementation for that is here: https://github.com/LearnBoost/socket.io-client/blob/master/lib/socket.js#L223-245 ).

    So what you should do different in your code is:

    io.connect('http://localhost:4000/news', { 'connect timeout': 5000 }); 
    // set connect timeout to 5 seconds
    

提交回复
热议问题