In this recipe, we will integrate WebSockets in a React Native application. We are going to use the Hello World of WebSockets applications, that is, a simple chat app. This app will allow users to send and receive messages.
Establishing real-time communication with WebSockets
Getting ready
To support WebSockets on React Native, we will need to run a server to handle all connected clients. The server should be able to broadcast a message when it receives a message from any of the connected clients.
We'll start with a new, empty React Native app. We'll name it web-sockets. In the root of the project, let's add a server folder with an index.js file inside of it. If you don't already have it, you'll need...