I can't connect via socket io to my server, it times out. ์์ผ io๋ฅผ ํตํด ๋ด ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์๊ฐ์ด ์ด๊ณผ๋ฉ๋๋ค.
In react-native: ๋ฐ์ ๋ค์ดํฐ๋ธ์์:
import io from 'socket.io-client';
const BACKEND = 'my socketio server url'
const sock = io(BACKEND, { transports: ['websocket'], forceNew: true });
sock.on('connected', () => {
debugger;
})
The debug logs look like: ๋๋ฒ๊ทธ ๋ก๊ทธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
socket.io-client:url parse <my url> +0ms
browser.js:133 socket.io-client ignoring socket cache for <my url> +0ms
browser.js:133 socket.io-client:manager readyState closed +0ms
browser.js:133 socket.io-client:manager opening <my url> +1ms
browser.js:133 engine.io-client:socket creating transport "websocket" +0ms
browser.js:133 engine.io-client:socket setting transport websocket +3ms
browser.js:133 socket.io-client:manager connect attempt will timeout after 20000 +6ms
browser.js:133 socket.io-client:manager readyState opening +2ms
socket.io-client:manager connect attempt timed out after 20000 +20s
browser.js:133 engine.io-client:socket socket close with reason: "forced close" +20s
browser.js:133 engine.io-client:socket socket closing - telling transport to close +2ms
browser.js:133 socket.io-client:manager connect_error +3ms
browser.js:133 socket.io-client:manager cleanup +1ms
browser.js:133 socket.io-client:manager will wait 899ms before reconnect attempt +1ms
browser.js:133 socket.io-client:manager attempting reconnect +912ms
Note : the best way (and by that we mean the only way ) to get a quick answer is to provide a failing test case by forking the following fiddle . ์ฐธ๊ณ : ๋น ๋ฅธ ๋ต๋ณ์ ์ป๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ(์ฆ , ์ ์ผํ ๋ฐฉ๋ฒ )์ ๋ค์ ๋ฐ์ด์ฌ๋ฆฐ ์ ๋ถ๊ธฐํ์ฌ ์คํจํ ํ ์คํธ ์ฌ๋ก๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ๋๋ค.
I expect to be able to connect to my socketio server, the same way I am able to in a web browser. ์น ๋ธ๋ผ์ฐ์ ์์์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๋ด socketio ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์๊ธฐ๋ฅผ ๊ธฐ๋ํฉ๋๋ค.
Looks like this is react-native's issue. ์ด๊ฒ์ react-native์ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค. Earlier versions of RN seem to work with socket.io, but 0.0.57 does not. ์ด์ ๋ฒ์ ์ RN์ socket.io์์ ์๋ํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง 0.0.57์์๋ ์๋ํ์ง ์์ต๋๋ค. Closing. ํ์.
enTry "socket.io-client": "2.0.4" "socket.io-client": "2.0.4"๋ฅผ ์๋ํ์ญ์์ค.
This may be socket.io bug ์ด๊ฒ์ socket.io ๋ฒ๊ทธ์ผ ์ ์์ต๋๋ค.
Try "socket.io-client": "2.0.4" "socket.io-client": "2.0.4"๋ฅผ ์๋ํ์ญ์์ค.
This may be socket.io bug ์ด๊ฒ์ socket.io ๋ฒ๊ทธ์ผ ์ ์์ต๋๋ค.
Yes it does work. ์, ์๋ํฉ๋๋ค.
enRN 0.52 ๋ฐ socket.io-client 2.0.4์์ ์ฌ์ ํ ์ด ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค.
en@noahprince22 can you please share your configuration ? @noahprince22 ๊ตฌ์ฑ์ ๊ณต์ ํด ์ฃผ์๊ฒ ์ต๋๊น?
I am currently using this and the issue still persist. ๋๋ ํ์ฌ ์ด๊ฒ์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๋ฌธ์ ๋ ์ฌ์ ํ ์ง์๋ฉ๋๋ค.
"react-native": "0.55.4",
"react": "16.3.1",
"socket.io-client": "^2.0.4",
"socket.io: "^2.2.0" //server side
en
any workaround? ์ด๋ค ํด๊ฒฐ ๋ฐฉ๋ฒ?
socket.io team please, this should work with RN, is a socket.io bug. socket.io ํ ์ ๋ฐ, ์ด๊ฒ์ RN๊ณผ ํจ๊ป ์๋ํด์ผ ํฉ๋๋ค. socket.io ๋ฒ๊ทธ์ ๋๋ค.
enHi @ningacoding , I managed to get it working with this configuration ์๋ ํ์ธ์ @ningacoding , ์ด ๊ตฌ์ฑ์ผ๋ก ์๋ํ๋๋ก ๊ด๋ฆฌํ์ต๋๋ค.
"react-native": "0.55.4",
"react": "16.3.1",
"socket.io-client": "^2.0.4",
"socket.io: "^1.0.0" //server side
In your react-native app use this ๋ฐ์ ๋ค์ดํฐ๋ธ ์ฑ์์ ์ด๊ฒ์ ์ฌ์ฉํ์ญ์์ค.
const socket = io(BASE_URL, {
secure: true,
transports: ['websocket'],
});
en
"react-native": "0.58.6", "๋ฐ์ ๋ค์ดํฐ๋ธ": "0.58.6",
"react": "16.6.3", "๋ฐ์": "16.6.3",
"socket.io-client": "^2.0.4", "socket.io-client": "^2.0.4",
Not working for me ๋๋ฅผ ์ํด ์ผํ์ง ์๋๋ค
enany solution? ์ด๋ค ํด๊ฒฐ์ฑ ? I'm facing the same thing ๋๋ ๊ฐ์ ์ผ์ ์ง๋ฉดํ๊ณ ์๋ค
enI have long since stopped working on the project that I was having this issue with. ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ ํ๋ก์ ํธ์์ ์์ ์ ์ค๋จํ ์ง ์ค๋์ ๋๋ค. If I remember correctly, I downgraded react-native to "solve' the problem. ๋ด๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ๊ธฐ์ตํ๋ค๋ฉด ๋ฌธ์ ๋ฅผ "ํด๊ฒฐ"ํ๊ธฐ ์ํด ๋ฐ์ ๋ค์ดํฐ๋ธ๋ฅผ ๋ค์ด๊ทธ๋ ์ด๋ํ์ต๋๋ค.
enExperiencing the same issue, has there been a fix yet? ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋๋ฐ ์์ง ํด๊ฒฐ๋์ง ์์์ต๋๊น? Anyone find any workarounds to implementing sockets in React Native? ๋๊ตฌ๋ ์ง React Native์์ ์์ผ์ ๊ตฌํํ๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์์ต๋๊น?
en@russellgoldman I had problems with RN 0.60.5 and socket.io. @russellgoldman RN 0.60.5 ๋ฐ socket.io์ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค. Release build did not connect to the server. ๋ฆด๋ฆฌ์ค ๋น๋๊ฐ ์๋ฒ์ ์ฐ๊ฒฐ๋์ง ์์์ต๋๋ค.
None of socket.io versions worked with RN 0.60.5: I tried versions 2.0.4, 2.1.1, 2.2.0. socket.io ๋ฒ์ ์ RN 0.60.5์์ ์๋ํ์ง ์์์ต๋๋ค. ๋ฒ์ 2.0.4, 2.1.1, 2.2.0์ ์ฌ์ฉํด ๋ณด์์ต๋๋ค.
Downgrading to RN 0.59.10 solved my problem. RN 0.59.10์ผ๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ฉด ๋ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
enHi @anttirauh and @russellgoldman , ์๋
ํ์ธ์ @anttirauh ๋ฐ @russellgoldman ,
I tried with RN 0.59.10 and Socket 2.0.4, but its not connecting on release build. RN 0.59.10 ๋ฐ ์์ผ 2.0.4๋ก ์๋ํ์ง๋ง ๋ฆด๋ฆฌ์ค ๋น๋์์ ์ฐ๊ฒฐ๋์ง ์์์ต๋๋ค.
Can you please help me? ์ ๋ฐ ๋ ์ข ๋์ ์ค ์ ์๋?
@Ramesh21071993 socket.io๋ฅผ ๋ฒ์ 2.1.1๋ก ์ ๊ทธ๋ ์ด๋ํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
en@anttirauh , i tried with all these versions socket io (2.0.4, 2.1.1, 2.2.0) and react-native versions (0.60, 0.59.10, 0.59.4) @anttirauh , ๋๋์ด ๋ชจ๋ ๋ฒ์ ์ ์์ผ io (2.0.4, 2.1.1, 2.2.0) ๋ฐ ๋ฐ์ ๋ค์ดํฐ๋ธ ๋ฒ์ (0.60, 0.59.10, 0.59.4)์ผ๋ก ์๋ํ์ต๋๋ค.
In server side also socket io 2.0.4. ์๋ฒ ์ธก์์๋ ์์ผ io 2.0.4.
still that same issue sir, ์ฌ์ ํ ๊ฐ์ ๋ฌธ์ ์
๋๋ค ์ ์๋,
But it works on RN 0.55.4 ๊ทธ๋ฌ๋ RN 0.55.4์์ ์๋ํฉ๋๋ค.
en@Ramesh21071993 My understanding (which is formed with heavy googling and own testing) is that: @ Ramesh21071993 ๋ด ์ดํด (๋ง์ ์ธํฐ๋ท ๊ฒ์ ๋ฐ ์์ฒด ํ ์คํธ๋ก ๊ตฌ์ฑ๋จ)๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
So my advice is only: try one time more with RN 0.59.10 and socket.io 2.1.1 and make sure that you clear build folder before building. ๊ทธ๋์ ์ ์กฐ์ธ์: RN 0.59.10 ๋ฐ socket.io 2.1.1๋ก ํ ๋ฒ ๋ ์๋ํ๊ณ ๋น๋ํ๊ธฐ ์ ์ ๋น๋ ํด๋๋ฅผ ์ง์ ๋์ง ํ์ธํ์ญ์์ค. And remove node_modules before yarn/npm. ๊ทธ๋ฆฌ๊ณ yarn/npm ์์ node_modules๋ฅผ ์ ๊ฑฐํ์ญ์์ค.
en@anttirauh Sir, below is my package.json. @anttirauh ์ ์๋, ์๋๋ ๋ด package.json์
๋๋ค. I did as what you told. ๋ง์ํ์ ๋๋ก ํ์ต๋๋ค. But nothing happen. ํ์ง๋ง ์๋ฌด ์ผ๋ ์ผ์ด๋์ง ์์ต๋๋ค. I remove build folder and node modules and again i install. ๋น๋ ํด๋์ ๋
ธ๋ ๋ชจ๋์ ์ ๊ฑฐํ๊ณ ๋ค์ ์ค์นํฉ๋๋ค.
Please help me on this to work, Past one month am trying ์ด ์์
์ ๋์์ฃผ์ธ์. ์ง๋ ํ ๋ฌ ๋์ ๋
ธ๋ ฅํ๊ณ ์์ต๋๋ค.
{ {
"name": "Track", "์ด๋ฆ": "ํธ๋",
"version": "0.0.1", "๋ฒ์ ": "0.0.1",
"private": true, "๋น๊ณต๊ฐ": ์ฌ์ค,
"scripts": { "์คํฌ๋ฆฝํธ": {
"start": "node node_modules/react-native/local-cli/cli.js start", "์์": "๋
ธ๋ node_modules/react-native/local-cli/cli.js ์์",
"test": "jest" "ํ
์คํธ": "๋๋ด"
}, },
"dependencies": { "์ข
์์ฑ": {
"react": "16.8.3", "๋ฐ์": "16.8.3",
"react-native": "0.59.10", "๋ฐ์ ๋ค์ดํฐ๋ธ": "0.59.10",
"socket.io": "2.1.1" "socket.io": "2.1.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.6.2", "@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2", "@babel/runtime": "^7.6.2",
"babel-jest": "^24.9.0", "๋ฐ๋ฒจ ๋๋ด": "^24.9.0",
"jest": "^24.9.0", "๋๋ด": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0", "metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.8.3" "๋ฐ์ ํ
์คํธ ๋ ๋๋ฌ": "16.8.3"
}, },
"jest": { "๋๋ด": {
"preset": "react-native" "์ฌ์ ์ค์ ": "๋ฐ์ ๋ค์ดํฐ๋ธ"
} }
} }
{ {
"name": "TRACK-Socket", "์ด๋ฆ": "ํธ๋ ์์ผ",
"version": "0.0.1", "๋ฒ์ ": "0.0.1",
"dependencies": { "์ข
์์ฑ": {
"amqplib": "^0.5.1", "amqplib": "^0.5.1",
"config": "^3.2.2", "๊ตฌ์ฑ": "^3.2.2",
"express": "^4.15.3", "์ต์คํ๋ ์ค": "^4.15.3",
"socket.io": "^2.1.1", "socket.io": "^2.1.1",
"ws": "^7.1.2" "ws": "^7.1.2"
} }
} }
Thanks ๊ฐ์ฌํด์
enFinally found a solution for React Native >= 0.60 after a couple of coffees and digging deep into engine.io - additional to a version conflict (with RN) there seems to be an issue with passing in the URI. ๋ง์ง๋ง์ผ๋ก ๋ช ์์ ์ปคํผ๋ฅผ ๋ง์๊ณ engine.io๋ฅผ ๊น์ด ํ๊ณ ๋ ํ React Native >= 0.60์ ๋ํ ์๋ฃจ์
์ ์ฐพ์์ต๋๋ค. ๋ฒ์ ์ถฉ๋(RN๊ณผ์)์ ์ถ๊ฐ๋ก URI๋ฅผ ์ ๋ฌํ๋ ๋ฐ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. When I pass an URI into socketIO, it gets turncated to the host and 'socket.io' appened. URI๋ฅผ socketIO์ ์ ๋ฌํ๋ฉด ํธ์คํธ๋ก ์ ํ๋๊ณ 'socket.io'๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. So socketIO("https://foo.bar/my/endpoint/socket.io")
will lead to socketIO trying to connect to https://foo.bar/socket.io
without showing it in the logs when throwing the xhr pull / socket error. ๋ฐ๋ผ์ socketIO("https://foo.bar/my/endpoint/socket.io")
๋ xhr pull / socket ์ค๋ฅ๋ฅผ ๋์ง ๋ ๋ก๊ทธ์ ํ์ํ์ง ์๊ณ https://foo.bar/socket.io
์ ์ฐ๊ฒฐ์ ์๋ํ๋ socketIO๋ก ์ด์ด์ง๋๋ค.
Here we go, how to get socket.io running on current versions of React Native : ํ์ฌ ๋ฒ์ ์ React Native์์ socket.io๋ฅผ ์คํํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
socket.io-client
version _2.1.1_ socket.io-client
๋ฒ์ _2.1.1_ ์ฌ์ฉ// package.json
{
"dependencies": {
"socket.io-client": "2.1.1"
}
}
const socket = socketIO('https://your.host.com/', {
path: '/path/to/socket.io/'
})
Hope to have saved you the time I spent on this issue ๐ ์ด ๋ฌธ์ ์ ์์ํ ์๊ฐ์ ์ ์ฝํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค ๐
en@rastapasta , i got an error like โ CLEARTEXT communication not permitted by network security policy โ, @rastapasta , " ๋คํธ์ํฌ ๋ณด์ ์ ์ฑ ์ ์ํด ํ์ฉ๋์ง ์๋ CLEARTEXT ํต์ "๊ณผ ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
Please tell me what to do ์ด๋ป๊ฒ ํด์ผํ ์ง ์๋ ค์ฃผ์ธ์
en@Ramesh21071993 if you can't use your endpoint via https (please consider it), add their hostnames to the exception lists. @Ramesh21071993 https๋ฅผ ํตํด ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ(๊ณ ๋ คํ์ญ์์ค) ํธ์คํธ ์ด๋ฆ์ ์์ธ ๋ชฉ๋ก์ ์ถ๊ฐํ์ญ์์ค.
for iOS: https://stackoverflow.com/a/30732693 iOS์ฉ: https://stackoverflow.com/a/30732693
for Android: https://stackoverflow.com/a/50834600 ์๋๋ก์ด๋์ฉ: https://stackoverflow.com/a/50834600
Sir, I tried that also but not able to do. ์ ์๋ ์ ๋ ํด๋ดค๋๋ฐ ์๋๋ค์. If you don't mind can you please give me any demo source files ๊ด์ฐฎ์ผ์๋ค๋ฉด ๋ฐ๋ชจ ์์ค ํ์ผ์ ์ฃผ์ธ์.
For long time I struck with this. ์ค๋ซ๋์ ๋๋ ์ด๊ฒ์ ๋ถ๋ช์ณค๋ค.
Am using ip and port sir ip ๋ฐ ํฌํธ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค ์ ์๋
en์ ๋ฌธ์ ์ ์ง์๋ฅผ ๋ฐ๋ฅด๊ณ ์ด ๊ตฌํ์ ์กฐ์ ํ์ญ์์ค:
import socketIO from 'socket.io-client'
const socket = socketIO('http://8.8.8.8:3000/', {
path: '/your/path/to/socket.io/'
reconnectionDelay: 1000,
reconnection: true,
reconnectionAttempts: Infinity,
jsonp: false
})
socket.on('connect', () => console.log('connected'))
socket.on('error', console.error)
socket.on('connect_error', console.error)
en
์ ์๋, ์๋ฒ ์ธก์์ socket io 2.1.1์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ด์ฐฎ์ต๋๊น ์๋๋ฉด ๋ณ๊ฒฝํด์ผ ํ ์ฌํญ์ด ์์ต๋๊น?
en@Lizhooh rn์์ whazzup์ ์ฐพ๋ ํดํค ๋ฐฉ๋ฒ: node_modules
engine.io-client/blob/master/lib/transports/ ์์ self.onError
console.log(err)
๋ฅผ ์์ญ์ด ํจ์น polling-xhr.js #L131
@Ramesh21071993 Is your issue resolved? @Ramesh21071993 ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๊น? I am facing the same issue. ๋๋ ๊ฐ์ ๋ฌธ์ ์ ์ง๋ฉด ํด์๋ค. Tried everything mentioned in above comments. ์์ ์๊ฒฌ์์ ์ธ๊ธํ ๋ชจ๋ ๊ฒ์ ์๋ํ์ต๋๋ค.
en@rastapasta I followed what you have suggested above. @rastapasta ์์์ ์ ์ํ ๋ด์ฉ์ ๋ฐ๋์ต๋๋ค. My socket connection happens and then immediately disconnects. ๋ด ์์ผ ์ฐ๊ฒฐ์ด ๋ฐ์ํ ๋ค์ ์ฆ์ ์ฐ๊ฒฐ์ด ๋์ด์ง๋๋ค. I get timeout error infinitely. ์๊ฐ ์ด๊ณผ ์ค๋ฅ๊ฐ ๋ฌดํํ ๋ฐ์ํฉ๋๋ค. However, whenever I click on some component which makes a network call, the socket connects and immediately disconnects. ๊ทธ๋ฌ๋ ๋คํธ์ํฌ ํธ์ถ์ ์ํํ๋ ์ผ๋ถ ๊ตฌ์ฑ ์์๋ฅผ ํด๋ฆญํ ๋๋ง๋ค ์์ผ์ด ์ฐ๊ฒฐ๋๊ณ ์ฆ์ ์ฐ๊ฒฐ ํด์ ๋ฉ๋๋ค. If I don't do any network call after first socket disconnect, it would stay in the same state. ์ฒซ ๋ฒ์งธ ์์ผ ์ฐ๊ฒฐ ํด์ ํ ๋คํธ์ํฌ ํธ์ถ์ ์ํํ์ง ์์ผ๋ฉด ๋์ผํ ์ํ๋ก ์ ์ง๋ฉ๋๋ค. Please, could you help? ๋์์ฃผ์๊ฒ ์ด์?
socket = io('http://IP:31515', { ์์ผ = io('http://IP:31515', {
path: '/socketio', //I have given this is the path in my socket server as well as my kubernetes ingress file to route to that port path: '/socketio', //์ด๊ฒ์ ๋ด ์์ผ ์๋ฒ์ ๊ฒฝ๋ก์ ํด๋น ํฌํธ๋ก ๋ผ์ฐํ
ํ๊ธฐ ์ํ ๋ด kubernetes ์์ ํ์ผ์
๋๋ค.
transports: ['websocket'], ์ ์ก: ['์น ์์ผ'],
reconnectionDelay: 1000, ์ฌ์ฐ๊ฒฐ ์ง์ฐ: 1000,
reconnection: true, ์ฌ์ฐ๊ฒฐ: ์ฌ์ค,
reconnectionAttempts: Infinity, ์ฌ์ฐ๊ฒฐ ์๋ ํ์: ๋ฌดํ๋,
// timeout: 30000, // ์๊ฐ ์ด๊ณผ: 30000,
jsonp: false jsonp: ๊ฑฐ์ง
}); });
things that I have tried: ๋ด๊ฐ ์๋ํ ๊ฒ๋ค :
Note: the same server and kubernetes conf work for any node.js socket client as well as my react js web app. ์ฐธ๊ณ : ๋์ผํ ์๋ฒ ๋ฐ kubernetes conf๋ ๋ชจ๋ node.js ์์ผ ํด๋ผ์ด์ธํธ์ ๋ฐ์ js ์น ์ฑ์์ ์๋ํฉ๋๋ค. I am only facing this issue for React Native app in debug as well as release mode. ๋๋ฒ๊ทธ ๋ฐ ๋ฆด๋ฆฌ์ค ๋ชจ๋์์ React Native ์ฑ์ ๋ํด์๋ง ์ด ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค.
en๋๊ตฌ๋ ์ง ์์ ๋ฌธ์ ์ ๋ํด ์๋ฌด ์๊ฐ์ด ์์ต๋๊น?
en@calqlum123 @calqlum123
Please make sure to ๋ฐ๋์ ํ์ธํด์ฃผ์ธ์
Can anyone please share a complete working example for both client and server? ๋๊ตฌ๋ ์ง ํด๋ผ์ด์ธํธ์ ์๋ฒ ๋ชจ๋์ ๋ํ ์์ ํ ์์ ์์ ๋ฅผ ๊ณต์ ํ ์ ์์ต๋๊น? Because this is confusing. ์ด๊ฒ์ ํผ๋์ค๋ฝ๊ธฐ ๋๋ฌธ์ ๋๋ค.
en@Unforgiven-wanda @์ฉ์๋ฐ์ง ๋ชปํ ์๋ค
foodsharing.network 's socket io: foodsharing.network ์ ์์ผ io:
I am using "react-native": "0.61.5" and "socket.io-client": "^2.1.1", "react-native": "0.61.5" ๋ฐ "socket.io-client": "^2.1.1"์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
below is my code ์๋๋ ๋ด ์ฝ๋์ ๋๋ค
const socket = SocketIOClient('http://192.168.0.101:1234',{reconnect: true});
socket.connect();
socket.once("connect", () => {
console.log("[CLIENT] Connected to remote server, identificating.");
// this.sendIdentification();
});
socket.on('connect', () => {
console.log('connected to socket server');
});
The code is not able to connect to the server and I am also looking for the solution. ์ฝ๋๊ฐ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ผ๋ฉฐ ์๋ฃจ์ ์ ์ฐพ๊ณ ์์ต๋๋ค. I don't want to downgrade my react-native version. ๋ฐ์ ๋ค์ดํฐ๋ธ ๋ฒ์ ์ ๋ค์ด๊ทธ๋ ์ด๋ํ๊ณ ์ถ์ง ์์ต๋๋ค.
enyou must add this code in application tag ์ ํ๋ฆฌ์ผ์ด์
ํ๊ทธ์ ์ด ์ฝ๋๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
like below in AndroidManifest.xml AndroidManifest.xml์์ ์๋์ ๊ฐ์ด
I am using "react-native": "0.61.5" and "socket.io-client": "^2.1.1", "react-native": "0.61.5" ๋ฐ "socket.io-client": "^2.1.1"์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
below is my code ์๋๋ ๋ด ์ฝ๋์ ๋๋ค
const socket = SocketIOClient('http://192.168.0.101:1234',{reconnect: true}); socket.connect(); socket.once("connect", () => { console.log("[CLIENT] Connected to remote server, identificating."); // this.sendIdentification(); }); socket.on('connect', () => { console.log('connected to socket server'); });
The code is not able to connect to the server and I am also looking for the solution. ์ฝ๋๊ฐ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ผ๋ฉฐ ์๋ฃจ์ ์ ์ฐพ๊ณ ์์ต๋๋ค. I don't want to downgrade my react-native version. ๋ฐ์ ๋ค์ดํฐ๋ธ ๋ฒ์ ์ ๋ค์ด๊ทธ๋ ์ด๋ํ๊ณ ์ถ์ง ์์ต๋๋ค.
Can you try "ws://192.168.0.101:1234", instead of " http://192.168.0.101 :1234" " http://192.168.0.101 :1234" ๋์ "ws://192.168.0.101:1234"๋ฅผ ์๋ํ ์ ์์ต๋๊น?
en@Unforgiven-wanda React Native์ ์๊ฐ ์ฌ๊ธฐ์ ์ถ๊ฐ๋์์ต๋๋ค. https://github.com/socketio/socket.io/tree/master/examples/react-native
en๋ฐ์ ๋ค์ดํฐ๋ธ์์ "socket.io-client": "^3.0.4"์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
en@chiragpurohit71085 have you checked the example there: https://github.com/socketio/socket.io/tree/master/examples/react-native? @chiragpurohit71085 https://github.com/socketio/socket.io/tree/master/examples/react-native์์ ์์ ๋ฅผ ํ์ธํ์ จ์ต๋๊น?
I think that this is a problem of URL, could you please check if your server is reachable at http://192.168.x.y:z
? ์ด๊ฒ์ URL์ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค. http://192.168.x.y:z
์์ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์๋์ง ํ์ธํด ์ฃผ์๊ฒ ์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
Finally found a solution for React Native >= 0.60 after a couple of coffees and digging deep into engine.io - additional to a version conflict (with RN) there seems to be an issue with passing in the URI. ๋ง์ง๋ง์ผ๋ก ๋ช ์์ ์ปคํผ๋ฅผ ๋ง์๊ณ engine.io๋ฅผ ๊น์ด ํ๊ณ ๋ ํ React Native >= 0.60์ ๋ํ ์๋ฃจ์ ์ ์ฐพ์์ต๋๋ค. ๋ฒ์ ์ถฉ๋(RN๊ณผ์)์ ์ถ๊ฐ๋ก URI๋ฅผ ์ ๋ฌํ๋ ๋ฐ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. When I pass an URI into socketIO, it gets turncated to the host and 'socket.io' appened. URI๋ฅผ socketIO์ ์ ๋ฌํ๋ฉด ํธ์คํธ๋ก ์ ํ๋๊ณ 'socket.io'๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. So
socketIO("https://foo.bar/my/endpoint/socket.io")
will lead to socketIO trying to connect tohttps://foo.bar/socket.io
without showing it in the logs when throwing the xhr pull / socket error. ๋ฐ๋ผ์socketIO("https://foo.bar/my/endpoint/socket.io")
๋ xhr pull / socket ์ค๋ฅ๋ฅผ ๋์ง ๋ ๋ก๊ทธ์ ํ์ํ์ง ์๊ณhttps://foo.bar/socket.io
์ ์ฐ๊ฒฐ์ ์๋ํ๋ socketIO๋ก ์ด์ด์ง๋๋ค.Here we go, how to get socket.io running on current versions of React Native : ํ์ฌ ๋ฒ์ ์ React Native์์ socket.io๋ฅผ ์คํํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
socket.io-client
version _2.1.1_socket.io-client
๋ฒ์ _2.1.1_ ์ฌ์ฉHope to have saved you the time I spent on this issue ๐ ์ด ๋ฌธ์ ์ ์์ํ ์๊ฐ์ ์ ์ฝํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค ๐
en