Skip to content

[question]Can messages be send to client outside main thread? #94

Closed

Description

@habi498

Hi i am planning to run a websocket server in a separate thread from my main program. I am new to mutex, lock and unique_lock. I have saved the client pointer from 'onmessage' function. Can i safely use ws_sendframe from my main program using this pointer.

Activity

  1. Theldus commented on Aug 21, 2024

    @Theldus
    Owner

    Hi @habi498,
    Yes, you can.
    Just be careful if your client disconnects... since the list of clients in wsServer is static, reusing the pointer of a connection that has already been closed may result in sending a message to a client that does not exist, or even to another client.

  2. habi498 commented on Aug 22, 2024

    @habi498
    Author

    Hi Theldus,
    Thanks for reply. Also i will take care not to use client pointer after they disconnect

  3. Theldus commented on Sep 5, 2024

    @Theldus
    Owner

    Just be careful if your client disconnects... since the list of clients in wsServer is static, reusing the pointer of a connection that has already been closed may result in sending a message to a client that does not exist, or even to another client.

    Since this is no longer a issue (thanks to PR #96), I'm going to close this. Please feel free re-open it or create new issues if you feel the need =).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions