简体   繁体   English

React Native-iOS Real Device-套接字IO Web套接字不起作用

[英]React Native - iOS Real Device - Socket IO Web Sockets not Working

I have ran into an issue with socket events not hitting the server. 我遇到了套接字事件未触及服务器的问题。 I have an application that uses SocketIO. 我有一个使用SocketIO的应用程序。 The application works great when I use iOS Simulator. 当我使用iOS Simulator时,该应用程序运行良好。 As soon as I try to run my app on a real device socket events are not hitting the server. 一旦我尝试在真实设备上运行我的应用程序,套接字事件就不会到达服务器。 This is the case in both localhost and the instance located on AWS. 本地主机和位于AWS上的实例都属于这种情况。

When I press a button that should send a socket event to the server I get nothing in the console in Xcode. 当我按下一个应该向服务器发送套接字事件的按钮时,我在Xcode的控制台中什么也没得到。 The only thing I can see is an initial error that seems to happen continuously as soon as the application is built and launched. 我唯一能看到的是一个初始错误,该错误似乎在构建和启动应用程序后立即发生。

2019-01-30 07:12:38.533860-0800 Moder8[1033:191786] [] nw_socket_handle_socket_event [C512.1:1] Socket SO_ERROR [61: Connection refused]
2019-01-30 07:12:38.536864-0800 Moder8[1033:191786] [] nw_socket_connect [C512.2:1] connectx(7, [srcif=0, srcaddr=<NULL>, dstaddr=::1.8097], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [61: Connection refused]
2019-01-30 07:12:38.537119-0800 Moder8[1033:191786] [] nw_socket_connect [C512.2:1] connectx failed (fd 7) [61: Connection refused]
2019-01-30 07:12:38.537176-0800 Moder8[1033:191786] [] nw_socket_connect connectx failed (fd 7) [61: Connection refused]
2019-01-30 07:12:38.538112-0800 Moder8[1033:190902] [] nw_connection_get_connected_socket [C512] Client called nw_connection_get_connected_socket on unconnected nw_connection
2019-01-30 07:12:38.538230-0800 Moder8[1033:190902] TCP Conn 0x282234840 Failed : error 0:61 [61]
2019-01-30 07:12:40.115642-0800 Moder8[1033:191786] [] nw_socket_handle_socket_event [C513.1:1] Socket SO_ERROR [61: Connection refused]
2019-01-30 07:12:40.115716-0800 Moder8[1033:191786] [] nw_socket_handle_socket_event [C514.1:1] Socket SO_ERROR [61: Connection refused]
2019-01-30 07:12:40.116498-0800 Moder8[1033:191786] [] nw_socket_handle_socket_event [C513.2:1] Socket SO_ERROR [61: Connection refused]
2019-01-30 07:12:40.116561-0800 Moder8[1033:191786] [] nw_socket_handle_socket_event [C514.2:1] Socket SO_ERROR [61: Connection refused]
2019-01-30 07:12:40.116698-0800 Moder8[1033:190953] [] nw_connection_get_connected_socket [C513] Client called nw_connection_get_connected_socket on unconnected nw_connection
2019-01-30 07:12:40.116715-0800 Moder8[1033:190953] TCP Conn 0x28221d380 Failed : error 0:61 [61]
2019-01-30 07:12:40.116755-0800 Moder8[1033:190953] [] nw_connection_get_connected_socket [C514] Client called nw_connection_get_connected_socket on unconnected nw_connection
2019-01-30 07:12:40.116768-0800 Moder8[1033:190953] TCP Conn 0x28221d2c0 Failed : error 0:61 [61]

The reason I am skeptical as to whether this has anything to do with the problem is because I get this same error when I use the Simulator and the socket events reach the server just fine. 我对此是否与该问题有怀疑的原因是,当我使用Simulator并且套接字事件到达服务器时,我遇到了同样的错误。

What I have done. 我做了什么。

I have searched Google and have read many references to related stuff including: 我搜索过Google,并阅读了许多有关相关内容的参考资料,包括:

React native socket io no events being emitted from client 反应本机套接字io不会从客户端发出任何事件

Getting "socket.error: [Errno 61] Connection refused" python paramiko 获取“ socket.error:[Errno 61]连接被拒绝” python paramiko

https://medium.com/@hr.hseyin_80381/8-steps-to-get-rid-of-error-nw-connection-get-connected-socket-connection-has-no-connected-handler-1bf622ca2332 https://medium.com/@hr.hseyin_80381/8-steps-to-get-rid-of-error-nw-connection-get-connected-socket-connection-has-no-connected-handler-1bf622ca2332

Can't connect to web socket react-native-meteor iOS 无法连接到Web socket react-native-meteor iOS

I almost feel like this is something ridiculously simple. 我几乎觉得这很简单。 I tried playing around with App Transport Security Settings but could not find anything that made a difference: 我尝试使用“应用程序传输安全设置”,但找不到任何有帮助的内容:

在此处输入图片说明

I figured out the problem. 我解决了这个问题。 iOS requires you to use the Mac IP address when connecting to localhost. iOS要求您在连接到本地主机时使用Mac IP地址。 I forgot to add my socket url into the env config file so it was pointing at localhost which obviously will not work for the localhost server instance or the one on AWS. 我忘记将套接字URL添加到env配置文件中,因此它指向的是localhost,这显然不适用于localhost服务器实例或AWS上的实例。

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

相关问题 React Native Button 绝对位置不适用于真正的 iOS 特定设备 - React Native Button absolute position not working on real iOS specific device React Native IOS 应用程序网络服务可在模拟器上运行,但不适用于真正的 IOS 设备 - React native IOS app web-services works on simulator but not real IOS device React-Native iOS 热重载和调试模式在真实设备中不起作用 - React-Native iOS hot reloading and debug mode not working in real device 真正的IOS设备不会发出网络请求-React Native - Real IOS Device will not make network requests - React Native 如何在真实设备上捆绑和部署React-Native iOS应用 - How to bundle and deploy React-Native iOS app on real device 如何在React Native项目的iOS真实设备中调试? - How to debug in iOS real device on React Native project? 仅在 Xcode 13.2.1 真实设备上反应本机 IOS 应用程序崩溃 - React native IOS app crashing on Xcode 13.2.1 real device only 如何在 iOS 上连接到真实设备上的本地主机? - How to connect to localhost on a real device in react native on iOS? 如何在React Native应用程序的iOS后台运行socket.io? - How to run socket.io in the background on iOS in a React Native app? React Native:我可以在iOS模拟器上运行应用程序,但不能在真实设备上运行 - React native: I can run the application on iOS simulator but not on real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM