Giter VIP home page Giter VIP logo

wsc's Introduction

WSC

codecov

WSC (WebSocket Channel) is a library that can be used to manage github.com/gorilla/websocket using channels.

It provides 2 main functions:

  • func Connect(ctx context.Context, url string, config Config) (Websocket, *http.Response, error)
  • func Accept(ctx context.Context, conn WSConnection, config Config) (Websocket, error)

The interface WSConnection is used to interract with the websocket:

// Websocket is the interface of channel based websocket.
type Websocket interface {

  // Reads returns a channel where the incoming messages are published.
  // If nothing pumps the Read() while it is full, new messages will be
  // discarded.
  //
  // You can configure the size of the read chan in Config.
  // The default is 64 messages.
  Read() chan []byte

  // Write writes the given []byte in to the websocket.
  // If the other side of the websocket cannot get all messages
  // while the internal write channel is full, new messages will
  // be discarded.
  //
  // You can configure the size of the write chan in Config.
  // The default is 64 messages.
  Write([]byte)

  // Done returns a channel that will return when the connection
  // is closed.
  //
  // The content will be nil for clean disconnection or
  // the error that caused the disconnection. If nothing pumps the
  // Done() channel, the error will be discarded.
  Done() chan error

  // Close closes the websocket.
  //
  // Closing the websocket a second time has no effect.
  // A closed Websocket cannot be reused.
  Close(code int)

  // Error returns a channel that will return errors like
  // read or write discards and other errors that are not
  // terminating the connection.
  //
  // If nothing pumps the Error() channel, the error will be discarded.
  Error() chan error
}

wsc's People

Contributors

primalmotion avatar kevincantu avatar

Watchers

 avatar

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.