Websocket - Why does not every client receive the message?

0

Hello!

I have implemented a websocket server using this tutorial from AWS. I use the websocket to send real-time messages between my Unity project (simple desktop app) and a website.

Example:

When I send the following message then a button on the website should be clickable for everyone.

{"action": "sendmessage", "message": "button"}

However, out of the 200 connected clients, only 20 are actually receiving the message and able to click the button.

Sending a message in C#:

void SendMessage()
    {
        var msg = new 
        {
            action = "sendmessage",
            message = "button"
        };
        _ws.Send(JsonConvert.SerializeObject(msg));
    }

Receiving messages in Javascript:

const socket = new WebSocket("wss://xyz.execute-api.eu-central-1.amazonaws.com/x");
socket.onmessage = (event) => {
  if (event.data == "button") 
  {
    button.disabled = false;
  }

I followed all the settings in the AWS console as per the tutorial linked above. Do you have any idea what should be the problem?

1 Answer
-2

You did not show that code in your example, but you must iterate over all connection in order to send a message to all clients. Are you scanning the DynamoDB table properly? Are you reading all pages (using the next toekn)?

Add some debug messages to your server code and make sure that you are actually trying to send to all clients, and if you are, print any responses to check for errors.

Also, I am not sure what the _ws.Send does. In order to send a message on a web socket you must call the postToConnection API.

profile pictureAWS
EXPERT
Uri
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions