简体   繁体   English

React Native socketio无法连接到Node.js服务器(浏览器可以访问该服务器)

[英]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. 我正在使用socketio将React本机应用程序连接到Azure上的nodejs服务器。 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. 因此我发现问题出在Azure虚拟机上。 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 这确实是一个天真的错误,但是我还是Azure的新手,所以我想将答案发布给可能遇到相同问题的任何人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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