Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to connect to localhost Meteor app #82

Closed
jankapunkt opened this issue Jan 11, 2022 · 3 comments
Closed

how to connect to localhost Meteor app #82

jankapunkt opened this issue Jan 11, 2022 · 3 comments
Labels
question Further information is requested

Comments

@jankapunkt
Copy link
Member

jankapunkt commented Jan 11, 2022

I am using expo and I am trying to connect to a Meteor app on localhost in dev mode (expo start; bundle is pushed to my real android phone, no emulator)

Meteor.connect('ws://localhost:8080/websocket')
Meteor.getData().ddp.socket.rawSocket.onerror = e => console.error(e);
Meteor.getData().ddp.socket.addListener("open", () => console.log("open"));
Meteor.getData().ddp.socket.addListener("close", () => console.log("close"));

which produces the following output:

close
close

Event {
  "isTrusted": false,
  "message": "Failed to connect to localhost/127.0.0.1:8080",
}
at meteor/connect.js:12:2 in connectMeteor
at node_modules/react-native/Libraries/WebSocket/WebSocket.js:258:8 in _eventEmitter.addListener$argument_1
at node_modules/react-native/Libraries/vendor/emitter/_EventEmitter.js:135:10 in EventEmitter#emit

Dependencies:

    "@babel/preset-react": "^7.16.0",
    "@expo/vector-icons": "^12.0.5",
    "@meteorrn/core": "^2.3.0",
    "@react-native-community/netinfo": "^7.1.7",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.2.5",
    "@react-navigation/stack": "^6.0.11",
    "babel-preset-es2015": "^6.24.1",
    "colors": "1.4.0",
    "expo": "~43.0.3",
    "expo-app-loading": "^1.2.1",
    "expo-font": "~10.0.3",
    "expo-speech": "~10.0.3",
    "expo-splash-screen": "~0.13.5",
    "i18next": "^21.5.4",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-i18next": "^11.14.3",
    "react-native": "^0.64.3",
    "react-native-elements": "^3.4.2",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.8.0",
    "react-native-tts": "^4.1.0",
    "react-native-vector-icons": "^9.0.0",
    "react-native-web": "~0.17.5"

Is this expected; did I do something wrong here?

@jankapunkt jankapunkt added the bug Something isn't working label Jan 11, 2022
@TheRealNate
Copy link
Collaborator

Hey @jankapunkt, if you're pushing the bundle to a physical device localhost will not be accessible as localhost is only available on the same device the Meteor app is being run from. Your best bet is to locate the LAN IP address (https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses) for your machine running Meteor and connect to that. For example: ws://192.168.1.123:8080/websocket (that IP address is completely made up, you'll need to find the correct one for your machine).

Here is a StackOverflow question on this: https://stackoverflow.com/questions/47417766/calling-locally-hosted-server-from-expo-app. They have a different route where they dynamically access the IP address of your machine. It is up to you which option you prefer.

I'm removing the bug tag as I don't believe at this time that this is related to an issue with this package, however I will leave the issue open for now. Please close if you're able to solve your problem.

@TheRealNate TheRealNate added question Further information is requested and removed bug Something isn't working labels Jan 14, 2022
@jankapunkt
Copy link
Member Author

Hi thank you yes that fixed it. I would add this to the documentation as a PR so others won't jump into that trap, what do you think?

@TheRealNate
Copy link
Collaborator

@jankapunkt absolutely agree. I'll add some more details soon but for now I've added a link to this issue in the README under Basic Usage. I'll also close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants