2011-08-10 2 views
11

클라이언트 측에서 전송 유형을 정의하고 파이어 폭스 XHR 폴링, 그래서 이 같은 클라이언트 측에서 전송의 유형을 정의하려고 :내가 IE를위한 JSONP 폴링을 사용할 필요가

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits); 
      var socket = io.connect(VG.NODE_SERVER_URL,{ 
        transports:['xhr-polling'] 
      }); 
    } else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
      var socket = io.connect(VG.NODE_SERVER_URL,{ 
        transports:['jsonp-polling'] 
      }); 
    } else { 
      var socket = io.connect(VG.NODE_SERVER_URL); 
    } 

Firefox에서 테스트하고 socket.io-client lib에 로깅을 추가했습니다.

에서

https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1509

option.transports 오른쪽 인 ["xhr-polling", "flashsocket", "htmlfile", "xhr-polling", "jsonp-polling"]이다. 그러나

https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1679

에서 나는 전송 내가 는 서버 측에 정의 된 것과 같은 순서를 가지고있는, ["htmlfile", "jsonp- polling", "xhr-polling"]로 변경 이유를 알고하지 않습니다.

왜 이전 옵션을 사용하지 않습니까?

+0

위의 질문이 무엇인지 모르겠습니다. 위의'xhr-polling' 등의 시퀀스가 ​​무시되고'htmlfile'이 먼저 나옵니 까? 이 문제는 socket.io'0.8.7'로 복제됩니까? –

+0

질문 해 주셔서 감사합니다! FireFox로 내 악몽에 대한 대답이었습니다. Socket.io 문서는 너무 나쁘다 .. 교통 수단을 찾은 유일한 장소입니다. :) –

답변

18

버그는 이제 socket.io 버전 0.9.6에서 해결해야 ... 클라이언트에 전송을 설정할 수 있으며 작동 고급 :

socket = io.connect(HOST_REMOTE, { 
    transports: ['xhr-polling'] 
}); 
버전 1.0.0에서

이상 :

socket = io.connect(HOST_REMOTE, { 
    transports: ['polling'] 
}); 
+2

현재 (1.3.3) 소스는 'xhr-polling'보다는 'polling'을 사용하고있는 것 같습니다. –

+0

xhr 폴링 및 connet ios, android 및 html5 폴링을 사용하는 경우 언제든지 연결 해제 소켓과 같은 문제가 발생할 수 있습니다. –

1

socket.io.client에 버그가 있습니다.

그래서 당신은 내가 이것을 사용할 수 있습니다,

function Socket (options) { 
this.options = { 
    port: 80 
    , secure: false 
.... 
}; 

io.util.merge(this.options, options); 
.... 
}; 

io.util.merge(this.options, options,0);....