Git Product home page Git Product logo

Comments (6)

dhbaird avatar dhbaird commented on August 10, 2024

I'd like to help you get this working, but I'm going to need more information. Can you post a gist with the most minimal example possible that illustrates your issue?

from easywsclient.

phlegx avatar phlegx commented on August 10, 2024

See my sample code here :)
https://gist.github.com/phlegx/a1ac7869ac69a177616d

PROBLEM: After the wss->send("PING"); the connection get closed. Why?

EDIT: I have see that easywsclient don't holds the connection. If I use a javascript client all works fine! Any idea?
EDIT2: If I use the simple em-websocket all works fine!

from easywsclient.

dhbaird avatar dhbaird commented on August 10, 2024

Let's break this into three distinct issues.

  1. The way you are accessing wss from multiple threads is not safe. You'll need to guard each access to wss with a lock, here's an example: https://gist.github.com/dhbaird/c8f57409cdb35f769759 (there's probably a simpler way to do this, with less locking or fewer threads, but this gets you started with better thread safety)
  2. It looks like an auto-reconnect feature might be useful to incorporate into easywsclient.
  3. When I try your code with ws://echo.websocket.org (instead of ws://192.168.1.10:3000), I don't get disconnected, so your issue about frequent disconnection appears to be a localized issue with your server. Do you know how long it takes to get disconnected? What server are you using?

from easywsclient.

phlegx avatar phlegx commented on August 10, 2024

Nice sample code! Thx πŸ‘ i'm happy :D
I check this code and your questions and write you back...

:D

from easywsclient.

codervinod avatar codervinod commented on August 10, 2024

Hi dhbaird, I am trying to use library and would like to implement full duplex communication. Basically create 2 threads and send messages from one thread and receive messages in other thread. Is this easily possible? Your solution will make communication half duplex as mutex prevents sending and receiving at the same time,

from easywsclient.

dhbaird avatar dhbaird commented on August 10, 2024

@VinodG - You could open two (or more) web socket connections, one per thread. Then you can get even better than full duplex :) I am willing to consider API ideas that can address this issue in a generic way (i.e. the details of threading or mutexes should not be built into this library, unless it is done in a generic way that is optional; But if the API can be updated in a way that makes it more useful to a user who wants to use threads and mutexes from outside of this library, then that is worth looking into.).

from easywsclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.