A simple Node.js message relay for Docker for transmitting to Socket.IO clients.
- Run the Docker service.
- Create a listener on the client, such as a web page.
- Send messages using cURL or your favorite REST client.
For more information, see my nodejs-simple-message-relay example and screenshot.
Issue the following command to run in Docker:
docker run -p 3000:3000 --name socketio-relay -e API_KEY=MY_SECRET_API_KEY hendridm/socketio-relay
See Client Side Example Code or demo.html for an example of using the Socket.IO browser client to receive messages.
API_KEY
- The API key required to send messages to clients.DEBUG
- Add-e DEBUG=1
to display incoming messages to the console.
Once you have to service running and one or more clients connected, you can send messages to them using your favorite REST client. You can send any data you like as long as it's in JSON. For example, to send a message to the included demo.html, you could issue the following command:
curl --location --request POST 'http://localhost:3000/socket/my-socket-name?api_key=MY_SECRET_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{ "message": "Hello World!" }'
Note that "my-socket-name" in the endpoint above must match the name of the socket that you are listening to in the client (see demo.html). In this way, you can set different listeners and send different messages to different sockets.