Giter VIP home page Giter VIP logo

Comments (3)

vtolstov avatar vtolstov commented on August 24, 2024 1

thanks! i'm try to integrate ping/pong

from ws.

gobwas avatar gobwas commented on August 24, 2024

Hello!

So, am I understand it right, that conn is a tcp socket?
Thus, it depends on how client closes its connections – if it does just tcpconn.Close() (say, linux close() syscall), then you will receive error on your further Write() call. If client closes its connection gracefully with tcpconn.CloseWrite() (say, linux shutdown() syscall), then your Write() will still receive no error. Furthermore, if you doing your Write() calls not so frequently, even if client did close(), your socket and the main i/o loop will be active until you prepare next Write() call.

So my suggestion is to use additional goroutine that reads, say, 1 byte from client connection and when it returns io.EOF it means that client gone somehow. After that you could stop reading from ptmx (for example by killing spawned cmd) and return from the main loop.

Advanced solution may be to use epoll instance to handle events on multiple clients in one goroutine handler and close theirs cmd instances on io.EOF.

Other way to solve this issue is to implement simple ping/pong messaging at WebSocket layer or your application layer. WebSocket protocol provides ping/pong mechanism, which is also helpful when client disappeared due to network problems. When network down, that Read() approach will not work until tcp keepalive is used. So you may use WebSocket ping/pong messaging instead of tcp keepalive to solve both problem with client shutdown and with the network consistency.

from ws.

jjhesk avatar jjhesk commented on August 24, 2024

if that closes automatically by receiving 1005 from ws. should i still prepare to make ping pong message too?

1005 | No Status Recvd | Reserved.  Indicates that no status code was provided even though one was expected.
-- | -- | --

https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent

from ws.

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.