2

I am using socket.io.Some users sending message to me 'I can't send a message why ?'.I researched this problem,guess firewall or antivirus blocking websocket.If browser doesn't support the websocket,socket.io automatically switching to xhr polling,there is no problem.But If browser supports the websocket and antivirus or firewall is blocking the websocket,socket.io is not switching to xhr,and users can't send messages.How can I resolve this problem ?

Here is a websocket test report a user

http://websocketstest.com/result/244711

Websocket support is ok,data receive is no.

4

2 回答 2

0

I have found that a lot of users end up not being able to connect successfully with socket.io. Rather than trying to continually diagnose it, I have started to build my apps to have easy fallbacks to ajax. I can in fact, change my environment variable of useSocketIO to false, and the whole site, chatting, tipping, image sharing will fallback to ajax. This does not solve the underlying issue, but has saved me a lot of headaches in lost data not being transmitted.

pseudo code on the client

# check that I have a socket object
if socket != null
  # if not connected, try to reconnect
  if !socket.connected and !socket.connecting
    attemptResetOfSocketIO()

  # if now connected, send socket message
  if socket.connected or socket.connecting
    sendSocketMessage()
  else
    # not connected, send via ajax
    sendAjaxMessage()
else
  # no socket object, send via ajax
  sendAjaxMessage()
于 2013-08-14T19:01:36.167 回答
0

您可以在配置中将 Socket.IO 设置为仅使用 XHR 轮询:

io.configure(function () { 
  io.set("transports", ["xhr-polling"]);
});

请参阅官方文档中的配置 Socket.IO

于 2013-08-14T17:20:57.253 回答