客戶端的io.connect()
方法有沒有回調?我想打印一些關於連接失敗的文本,否則正常進行網站的套接字交互。Socket.IO中是否存在對io.connect()方法的回調?
9
A
回答
4
當然,結帳Socket.IO客戶端的文檔與例子有:
https://github.com/LearnBoost/socket.io-client#sockets-for-the-rest-of-us
socket.on('connect', function() {
// socket connected
});
2
在socket.io(1.3.x版)當前版本可以使用connect_error
事件或reconnect_failed
事件:
var socket = io(serverUrl);
socket.on('connect_error', function() {
console.log('Connection failed');
});
socket.on('reconnect_failed', function() {
console.log('Reconnection failed');
});
相關問題
- 1. socket.io的方法回調
- 2. redis sub/pub進出io.connect回調
- 3. 無法在socket.io中調用方法'on'
- 4. 是否可以在回調方法中使用reset()API方法?
- 5. Parse.com回調是否存在?
- 6. 在socket.io中處理回調的正確方法
- 7. 在Node.JS的類中使用Socket.IO回調的正確方法是什麼?
- 8. 在Socket.IO中發出調用之前是否有某個事件/方法?
- 9. 是否將主方法的返回值保存在堆棧中?
- 10. socket.io中發送方法的成功回調
- 11. Ruby Socket.IO回調
- 12. socket.io回調
- 13. ServiceStack v4中是否存在針對IDbConnectionFactory的Run擴展方法?
- 14. 在onDestroy之後是否可以調用回調方法?
- 15. 回調方法是否需要在node.js中定義?
- 16. 是否存在針對「您已登錄」的設計回調?
- 17. Math.Net中是否存在linspace()方法
- 18. 對象方法中的Javascript回調
- 19. 回調方法中的對象引用
- 20. Socket.io sessionStore,store.get方法不存在
- 21. 在調用未知方法時,OCMockito中是否有方法使存根失敗?
- 22. 在此方法實現中是否存在一個setter方法?
- 23. Backbone.js的:保存方法總是返回錯誤回調
- 24. 使用Smarty,是否可以在方法的返回值上調用方法?
- 25. 是否存在.closest()的替代方法?
- 26. 檢查jQuery的方法是否存在
- 27. 是否可以確定實例方法是否在原型方法中調用?
- 28. 如何查找回調是否是特定的方法?
- 29. 在Rails/Ruby中檢查對象是否存在的正確方法是什麼?
- 30. 如果CanCan回調存在,我是否需要Devise回調?
如果連接不成功? – birkof
檢查'connect_failed'事件:https://github.com/LearnBoost/socket.io-client#events – alessioalex
似乎在我的例子上這個事件不會啓動:( – birkof