Coder Social home page Coder Social logo

Comments (7)

lesismal avatar lesismal commented on June 13, 2024

For opening:

wsc, err := upgrader.Upgrade(...)
if err !=nil {
    ...
    return
}
// on open here

or register open handler by upgrader.OnOpen

For closing:

register close handler by upgrader.OnClose

You don't need to check the state of the ws conn when you use it everytime.

from nbio.

AnirudhDensityIntern avatar AnirudhDensityIntern commented on June 13, 2024

I want to make new connection and insure the previous websocket Should be closed, when I renew the older websocket thats why I need to check the webscocket is closed or not.

If you are not exporting isClosed Variable can you please make a function that exports the boolean value for the websocket

from nbio.

lesismal avatar lesismal commented on June 13, 2024

I think your way is not correct, that's useless to export isClosed coz:

  1. before OnClose is called it's healthy
  2. when OnClose is called, you know that it's closed now

That's why I said you don't need to check it's state.

from nbio.

AnirudhDensityIntern avatar AnirudhDensityIntern commented on June 13, 2024

I know when we call conn.close it closes the stream but in order to renew the websocket I will again do conn.close on the closed channel but in that case i will get error, So I need to ensure the websocket is closed or not before closing the channel also I dont want to make 2 same stream at any moment.

from nbio.

lesismal avatar lesismal commented on June 13, 2024

You don't need to re-create it when it's healthy!
You should re-create a new conn when OnClose.

Why do you want to re-create it when it's healthy?
Even you want to re-create a new conn when the old one is still healthy, you just need to close the old one and create the new one, you don't need to care about whether it returns err when you close the old one!

from nbio.

github-actions avatar github-actions commented on June 13, 2024

This issue is stale because it has been open for 30 days with no activity.

from nbio.

github-actions avatar github-actions commented on June 13, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

from nbio.

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.