Socket.io-client: react-native์—์„œ socket.io-client๋ฅผ ํ†ตํ•ด ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2018๋…„ 10์›” 31์ผ  ยท  37์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: socketio/socket.io-client

You want to: ์›ํ•˜๋Š” ์ž‘์—…:

  • [x] report a bug [x] ๋ฒ„๊ทธ ๋ณด๊ณ 
  • [ ] request a feature [ ] ๊ธฐ๋Šฅ ์š”์ฒญ

Current behaviour ํ˜„์žฌ ํ–‰๋™

I can't connect via socket io to my server, it times out. ์†Œ์ผ“ io๋ฅผ ํ†ตํ•ด ๋‚ด ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์‹œ๊ฐ„์ด ์ดˆ๊ณผ๋ฉ๋‹ˆ๋‹ค.

Steps to reproduce (if the current behaviour is a bug) ์žฌํ˜„ ๋‹จ๊ณ„(ํ˜„์žฌ ๋™์ž‘์ด ๋ฒ„๊ทธ์ธ ๊ฒฝ์šฐ)

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 . ์ฐธ๊ณ  : ๋น ๋ฅธ ๋‹ต๋ณ€์„ ์–ป๋Š” ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•(์ฆ‰ , ์œ ์ผํ•œ ๋ฐฉ๋ฒ• )์€ ๋‹ค์Œ ๋ฐ”์ด์˜ฌ๋ฆฐ ์„ ๋ถ„๊ธฐํ•˜์—ฌ ์‹คํŒจํ•œ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Expected behaviour ์˜ˆ์ƒ๋˜๋Š” ํ–‰๋™

I expect to be able to connect to my socketio server, the same way I am able to in a web browser. ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๋‚ด socketio ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค.

Setup ์„ค์ •

  • OS: iOS iPhone 10 simulator OS: iOS ์•„์ดํฐ 10 ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ
  • browser: React-native ๋ธŒ๋ผ์šฐ์ €: ๋ฐ˜์‘ ๋„ค์ดํ‹ฐ๋ธŒ
  • socket.io version: 2.1.1 socket.io ๋ฒ„์ „: 2.1.1
en

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

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 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๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • use socket.io-client version _2.1.1_ socket.io-client ๋ฒ„์ „ _2.1.1_ ์‚ฌ์šฉ
// package.json
{
  "dependencies": {
     "socket.io-client": "2.1.1"
   }
}
  • when setting up the client, define a host and a path ํด๋ผ์ด์–ธํŠธ๋ฅผ ์„ค์ •ํ•  ๋•Œ ํ˜ธ์ŠคํŠธ ์™€ ๊ฒฝ๋กœ๋ฅผ ์ •์˜ํ•˜์‹ญ์‹œ์˜ค.
const socket = socketIO('https://your.host.com/', {
  path: '/path/to/socket.io/'
})
  • and suddenly everything works as smooth as planed ๊ฐ‘์ž๊ธฐ ๋ชจ๋“  ๊ฒƒ์ด ๊ณ„ํš๋Œ€๋กœ ์›ํ™œํ•˜๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

Hope to have saved you the time I spent on this issue ๐Ÿ˜† ์ด ๋ฌธ์ œ์— ์†Œ์š”ํ•œ ์‹œ๊ฐ„์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค ๐Ÿ˜†

en

๋ชจ๋“  37 ๋Œ“๊ธ€

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. ํ์‡„.

en

Try "socket.io-client": "2.0.4" "socket.io-client": "2.0.4"๋ฅผ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค.
This may be socket.io bug ์ด๊ฒƒ์€ socket.io ๋ฒ„๊ทธ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

en

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. ์˜ˆ, ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

en

RN 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 ๋ฒ„๊ทธ์ž…๋‹ˆ๋‹ค.

en

Hi @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 ๋‚˜๋ฅผ ์œ„ํ•ด ์ผํ•˜์ง€ ์•Š๋Š”๋‹ค

en

any solution? ์–ด๋–ค ํ•ด๊ฒฐ์ฑ…? I'm facing the same thing ๋‚˜๋Š” ๊ฐ™์€ ์ผ์— ์ง๋ฉดํ•˜๊ณ ์žˆ๋‹ค

en

I 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. ๋‚ด๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๊ธฐ์–ตํ•œ๋‹ค๋ฉด ๋ฌธ์ œ๋ฅผ "ํ•ด๊ฒฐ"ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ˜์‘ ๋„ค์ดํ‹ฐ๋ธŒ๋ฅผ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œํ–ˆ์Šต๋‹ˆ๋‹ค.

en

Experiencing 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์œผ๋กœ ๋‹ค์šด ๊ทธ๋ ˆ์ด๋“œํ•˜๋ฉด ๋‚ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

en

Hi @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? ์ œ๋ฐœ ๋‚  ์ข€ ๋„์™€ ์ค„ ์ˆ˜ ์žˆ๋‹ˆ?

en

@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 ๋‚ด ์ดํ•ด (๋งŽ์€ ์ธํ„ฐ๋„ท ๊ฒ€์ƒ‰ ๋ฐ ์ž์ฒด ํ…Œ์ŠคํŠธ๋กœ ๊ตฌ์„ฑ๋จ)๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • socket.io stopped working with react-native about around RN version 0.57.4 socket.io๋Š” RN ๋ฒ„์ „ 0.57.4 ์ฃผ๋ณ€์—์„œ ๋ฐ˜์‘ ๋„ค์ดํ‹ฐ๋ธŒ ์ž‘์—…์„ ์ค‘๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค.
  • socket.io or some other component was fixed later and I managed to get it working with version combo: RN 0.59.10 + socket.io 2.1.1 socket.io ๋˜๋Š” ์ผ๋ถ€ ๋‹ค๋ฅธ ๊ตฌ์„ฑ ์š”์†Œ๋Š” ๋‚˜์ค‘์— ์ˆ˜์ •๋˜์—ˆ์œผ๋ฉฐ ๋ฒ„์ „ ์ฝค๋ณด: RN 0.59.10 + socket.io 2.1.1์—์„œ ์ž‘๋™ํ•˜๋„๋ก ๊ด€๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.
  • RN version 0.60.x is not working with any version of socket.io RN ๋ฒ„์ „ 0.60.x๋Š” ์–ด๋–ค ๋ฒ„์ „์˜ socket.io์—์„œ๋„ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

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 ์ด ์ž‘์—…์„ ๋„์™€์ฃผ์„ธ์š”. ์ง€๋‚œ ํ•œ ๋‹ฌ ๋™์•ˆ ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

App package.json ์•ฑ ํŒจํ‚ค์ง€.json

{ {
"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" "์‚ฌ์ „ ์„ค์ •": "๋ฐ˜์‘ ๋„ค์ดํ‹ฐ๋ธŒ"
} }
} }

Server Package.json ์„œ๋ฒ„ ํŒจํ‚ค์ง€.json

{ {
"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 ๊ฐ์‚ฌํ•ด์š”

en

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 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๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • use socket.io-client version _2.1.1_ socket.io-client ๋ฒ„์ „ _2.1.1_ ์‚ฌ์šฉ
// package.json
{
  "dependencies": {
     "socket.io-client": "2.1.1"
   }
}
  • when setting up the client, define a host and a path ํด๋ผ์ด์–ธํŠธ๋ฅผ ์„ค์ •ํ•  ๋•Œ ํ˜ธ์ŠคํŠธ ์™€ ๊ฒฝ๋กœ๋ฅผ ์ •์˜ํ•˜์‹ญ์‹œ์˜ค.
const socket = socketIO('https://your.host.com/', {
  path: '/path/to/socket.io/'
})
  • and suddenly everything works as smooth as planed ๊ฐ‘์ž๊ธฐ ๋ชจ๋“  ๊ฒƒ์ด ๊ณ„ํš๋Œ€๋กœ ์›ํ™œํ•˜๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

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

en

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

image

en

@Lizhooh rn์—์„œ whazzup์„ ์ฐพ๋Š” ํ•ดํ‚ค ๋ฐฉ๋ฒ•: node_modules engine.io-client/blob/master/lib/transports/ ์—์„œ self.onError console.log(err) ๋ฅผ ์›์ˆญ์ด ํŒจ์น˜ polling-xhr.js #L131

en

@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: ๋‚ด๊ฐ€ ์‹œ๋„ํ•œ ๊ฒƒ๋“ค :

  1. removing and adding transports option ์ „์†ก ์˜ต์…˜ ์ œ๊ฑฐ ๋ฐ ์ถ”๊ฐ€
    2.removing and add timeout 2. ํƒ€์ž„์•„์›ƒ ์ œ๊ฑฐ ๋ฐ ์ถ”๊ฐ€
  2. removing all parameters except path ๊ฒฝ๋กœ๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜ ์ œ๊ฑฐ
  3. adding pingTimeout and pingInterval in server socket configuration ์„œ๋ฒ„ ์†Œ์ผ“ ๊ตฌ์„ฑ์— pingTimeout ๋ฐ pingInterval ์ถ”๊ฐ€
  4. removing path from server and client and only keeping it in my kubernetes ingress file to route to that deployment/pod. ์„œ๋ฒ„ ๋ฐ ํด๋ผ์ด์–ธํŠธ์—์„œ ๊ฒฝ๋กœ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ํ•ด๋‹น ๋ฐฐํฌ/ํฌ๋“œ๋กœ ๋ผ์šฐํŒ…ํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด kubernetes ์ˆ˜์‹  ํŒŒ์ผ์—๋งŒ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

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 ๋ฐ˜๋“œ์‹œ ํ™•์ธํ•ด์ฃผ์„ธ์š”

  • add your host to the transport exception list (s. here ) ์ „์†ก ์˜ˆ์™ธ ๋ชฉ๋ก์— ํ˜ธ์ŠคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์‹ญ์‹œ์˜ค( ์—ฌ๊ธฐ ).
  • try it without manually defining the transports ์ „์†ก์„ ์ˆ˜๋™์œผ๋กœ ์ •์˜ํ•˜์ง€ ์•Š๊ณ  ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค.
  • monkey patch the console.log (s. here ) and check the error ์›์ˆญ์ด๋Š” console.log(s. here )๋ฅผ ํŒจ์น˜ํ•˜๊ณ  ์˜ค๋ฅ˜๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
en

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:

en

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. ๋ฐ˜์‘ ๋„ค์ดํ‹ฐ๋ธŒ ๋ฒ„์ „์„ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œํ•˜๊ณ  ์‹ถ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

en

you must add this code in application tag ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํƒœ๊ทธ์— ์ด ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
like below in AndroidManifest.xml AndroidManifest.xml์—์„œ ์•„๋ž˜์™€ ๊ฐ™์ด
. . . . . .

en

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 ์—์„œ ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ์ฃผ์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

en
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰