[英]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.