Socket
Socket
Sign inDemoInstall

wss

Package Overview
Dependencies
44
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wss

wrapper built upon ws module that provides standard server api only.


Version published
Weekly downloads
548
increased by1.11%
Maintainers
1
Install size
7.04 MB
Created
Weekly downloads
 

Readme

Source

wss

travis dependencies linter coverage node version license

wrapper built upon ws module that provides standard server api only.

usage with server creation
const {createServer} = require('wss')

createServer(function connectionListener (ws) {
  ws.send('welcome!')
  ws.on('message', (data) => {
    ws.send(data.toString()) // echo-server
  })
})
.listen(8080, function () {
  const {address, port} = this.address() // this is the http[s].Server
  console.log('listening on http://%s:%d (%s)', /::/.test(address) ? '0.0.0.0' : address, port)
})
usage with existent server
const {createServer} = require('http')
const {createServerFrom} = require('wss')

const http = createServer()
createServerFrom(http, function connectionListener (ws) {
  ws.send('welcome!')
  ws.on('message', (data) => {
    ws.send(data.toString()) // echo-server
  })
})
http.listen(8080)

wss

the ws.Server object is inherited from ws

wss.prototype.close([callback])

stops the server from accepting new connections.

wss.prototype.listen(handle[, callback])

the handle object can be set to either a server or socket (anything with an underlying handle member), or a {fd} object. This function is asynchronous. callback will be added as a listener for the listening event.

wss.prototype.listen(path[, callback])

start a unix socket server listening for connections on the given path. this function is asynchronous. callback will be added as a listener for the listening event.

wss.prototype.listen([port[, hostname[, backlog[, callback]]]])

begin accepting connections on the specified port and hostname. if the hostname is omitted, the server will accept connections on any ipv6 address (::) when ipv6 is available, or any ipv4 address (0.0.0.0) otherwise. omit the port argument, or use a port value of 0, to have the operating system assign a random port, which can be retrieved by using server.address().port after the listening event has been emitted.

to listen to a unix socket, supply a filename instead of port and hostname.

backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux. The default value of this parameter is 511. This function is asynchronous. callback will be added as a listener for the listening event.

Note: The server.listen() method may be called multiple times. Each subsequent call will re-open the server using the provided options.

wss.createServerFrom(server=http.Server|https.Server)

returns a new ws.Server based on given web server object. throws if no server is given.

wss.createServer([options[, connectionListener]])

returns a new ws.Server based on given options and connectionListener. underlaying https server is created when tls options have been provided as oftls.createServer(), otherwise it will fallback to a http implementation. the connectionListener is a function which is automatically added to the connection event.

Keywords

FAQs

Last updated on 06 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc