简体   繁体   中英

React Native socketio can' t connect to nodejs server (The server can be reached by browsers)

I'm using socketio to connect a react native app to a nodejs server on Azure. The server can be reached by browsers which makes me confident it's running and accessible, but my react native app can't connect to it. here's my code:


Client: (react native app inside the constructor)

socket = io('http://bahbishco.cloudapp.net/node', { jsonp: false, transports: ['websocket'] });

Server:

 let express = require('express'); let app = express(); let server = require('http').Server(app); let io = require('socket.io')(server); server.listen(8000); 

Any help would be great, thanks in advance.

So I found out the problem was with the Azure virtual machine. I learned that I need to create an "end point" with the port I want to reach. As well as provide it with a specific priority level. After doing so, the server worked fine. It's a naive mistake really but I'm still new with Azure, so I thought of posting the answer for anyone who might face the same issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM