JSPM

  • Created
  • Published
  • Downloads 16782
  • Score
    100M100P100Q135496F
  • License MIT

Use the Node `net` API in Chrome Apps

Package Exports

  • chrome-net

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chrome-net) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chrome-net

Use the Node net API in Chrome Apps

This module lets you use the Node.js net (TCP) API in Chrome Packaged Apps.

Instead of learning the quirks of Chrome's chrome.socket API for networking in Chrome Apps just use the higher-level node API you're familiar with. Then, compile your code with browserify and you're all set!

This module is used by webtorrent.

Installation

npm install chrome-net

Usage

Use node's net API, including all parameter list shorthands and variations.

Example TCP client:

var net = require('chrome-net')

var client = net.createConnection({
  port: 1337,
  host: '127.0.0.1'
})

client.write('beep')

client.on('data', function (data) {
  console.log(data)
})

// .pipe() streaming API works too!

Example TCP server:

var net = require('chrome-net')

var server = net.createServer()

server.on('listening', function () {
  console.log('listening')
})

server.on('connection', function (sock) {
  console.log('Connection from ' + sock.remoteAddress + ':' + sock.remotePort)
  sock.on('data', function (data) {
    console.log(data)
  })
})

server.listen(1337)

See nodejs.org for full API documentation: net

Contributing

To run tests, use npm test. The tests will run TCP and UDP servers and launch a few different Chrome Packaged Apps with browserified client code. The tests currently require Chrome Canary on Mac. If you're on Windows or Linux, feel free to send a pull request to fix this limitation.

MIT License

Copyright (c) Feross Aboukhadijeh & John Hiesey