socket.io로 채팅하고 https를 사용하여 내 앱을 설정하려고합니다. 그것은 http를 사용하고있을 때 작동했지만, 보안으로 인해 변경되었으므로 더 이상 채팅 서버에 연결할 수 없습니다.React Native로 https에 소켓 io를 연결할 수 없습니다.
실제로이 작업을 수행하지 않아도됩니다. 비슷한 문제가 발생했을 가능성이 있습니까?
내에서 내 채팅 서버에 연결 웹 프론트 엔드는 잘 작동하지만, 아이폰 OS 안드로이드뿐만 아니라위한 연결되지 않습니다 아래에이 코드를 시도 :
import './UserAgent.js';
import io from 'socket.io-client/socket.io';
const connectionOptions = {
jsonp : false,
transports: ['websocket'],
secure : true
};
export class App extends Component {
constructor() {
super();
this.state = {
chatThings: ''
};
this.chatUrl = 'https://chat.foo.info';
this.socket = io(this.chatUrl, connectionOptions)
}
connectToChatServer() {
let tries = 0;
var that = this;
setInterval(()=> {
that.socket.connect(that.chatUrl, connectionOptions);
console.log('CHAT url', that.chatUrl);
if (that.socket.connected) {
alert('Finally CONNECTED!!!!!!');
that.setState({
connected: socket.connected
});
}
tries = tries + 1;
}, 2500);
this.socket.on('error', (err)=> {
console.log('CHAT: error', err);
});
}
최신 ReactNative 최신 socket.io를 사용
UPDATE
window.navigator.userAgent = 'ReactNative';
var io = require('../node_modules/socket.io-client/dist/socket.io');
// -----------------------------------------------------------------------------------------------------------------
// Chat
// -----------------------------------------------------------------------------------------------------------------
Backend.prototype.connectToChatServer = function() {
let self = this;
this.dispatch(Actions.connectToChatServer());
const connectionOptions = {
jsonp : false,
secure : true,
transports: ['websocket']
};
log.info('CHAT IO CONNECTION');
this.socket = io(this.chatUrl, connectionOptions);
function authenticate() {
self.socket.emit('authenticate', {token: Store.getState().User.token});
}
........
사실 유일한 것은 내가 변화를 d는 소켓 io를 업데이트하고 ReactNative의 UserAgent를 사용하여 최신 버전에 응답합니다. 이 도움이되기를 바랍니다.
"socket.io-client": "^1.7.1",
"react-native": "^0.29.2", // this version worked, i have tested it on RN 43 too which works as well
안녕 BigPun86, 이제 문제를 해결 했습니까? –
@QuanVo 제 업데이트가 어떻게 든 도움이 되길 바랍니다. – BigPun86