skip to Main Content

I’m creating a react native application using Expo that connects to a WebSocket server to display data from the messages. The code I have works for Web and iOS but for some reason will not work on Android. It looks like the WebSocket connects, but no messages are received.

A test websocket server is wss://webserver14.sms-timing.com:10015 and the start message is START 19476@teamsportreading

Here is an expo snack of with the code https://snack.expo.dev/@waddas/cranky-soda.

Any help is greatly appreciated!

2

Answers


  1. Change the WebSocket URL from ws://webserver14.sms-timing.com:10015 to wss://webserver14.sms-timing.com:10015. This change will ensure that a secure WebSocket connection is established on both iOS and Android devices

    export default function App() {
      //...
      useEffect(() => {
        const socket = new WebSocket('wss://webserver14.sms-timing.com:10015');
    
        //...
    
      }, []);
    
    Login or Signup to reply.
  2. Make sure that in the app.json file that you have the necessary permissions set.

    "android": {
    "permissions": [
    "INTERNET"
    ]
    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search