I have my backend deployed on AWS EC2, it’s built with Django. I also have a NGINX reverse proxy sitting in front of it with SSL configured.
I’m currently using this code to make the connection
const setWebSocket = (ws_url: string, receiveMessageHandler: ReceiveMessageHandler) => {
// ws_url is something like wss://mybackendapi.com
wsRef.current = new WebSocket(ws_url ? wsUrl+"/ws/chat/" : "");
console.log(ws_url);
const ws = wsRef.current;
ws.onopen = () => {
console.log('connected to the server');
};
ws.onclose = (e) => {
};
ws.onerror = (e: Event) => {
console.log("websocket error", e);
};
ws.onmessage = (e) => {
console.log(e.data)
receiveMessageHandler(e);
};
};
When I use Expo Go on my phone (tried both android and IOS device) to test the react native app, the websocket connects just fine using the same endpoint.
But when I use simulator on my M2 macbook, I get the following error (logged in terminal)
websocket error {"isTrusted": false, "message": "The operation couldn’t be completed. Network is down"}
Every other http request works on the simulator as well, it’s only the websocket connection that is giving me trouble
Anyone know why this might be happening?
Apple Jem is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.