npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

winrt-net

v1.0.6

Published

WinRT (Windows App) wrapper for node net module

Downloads

8

Readme

winrt-net

Use the Node net API in Windows Apps (WinRT)

This module lets you use the Node.js net (TCP) API in Windows Universal Apps (WinRT).

Instead of learning the quirks of WinRT's StreamSocket and StreamSocketListener APIs for networking in Windows Apps just use the higher-level node API you're familiar with. ~~Then, compile your code with browserify and you're all set!~~ Then install this module through JSPM, rename it in your config file and you're all set!

Installation & Usage

1) Install the module through JSPM

jspm install npm:winrt-net

2) Rename winrt-net to net in your SystemJS/JSPM config file

Why?

JSPM has its own module that gets installed whenever you or your dependecy uses net module. And it does next to nothing because browsers don't do TCP.

how?

In JSPM config file there is property map with names and mappings of all modules. This is an example of JSPM 0.17 jspm.config.js

map: {
  "winrt-net": "npm:[email protected]",
  "events": "github:jspm/[email protected]",
  "process": "github:jspm/[email protected]",
  ...

you change the name like so

map: {
  "net": "npm:[email protected]",
  ...

and that forces JSPM to load this module whenever there is require('net') or import net from 'net' in your code or dependencies. It also uses the original Node net if you run your code in Node through jspm run. (more on that in chapter Building & Testing)

Usage

Example TCP client:

import net from 'net';

var port = 22112;

var server = net.createServer(function(socket) {
	console.log('connection', socket.remoteAddress + ":" + socket.remotePort);
	socket.on('data', function (data) {
		console.log(data.toString())
	})
})
.listen(port)
.on('listening', function () {
  console.log('listening')
});

Example TCP server:

import net from 'net';

var client = net.connect(22112, 'localhost')
client.write('Hello server')
client.on('data', function (data) {
	console.log('received data', data.toString());
})

Or you can skip step 2) and just use import net from 'winrt-net';

See nodejs.org for full API documentation: net

Keep in mind

supporting other platforms

If you write Chrome Packaged App you are probbably looking or similar module chrome-net.

If you however support both WinRT and Chrome you should instead install module flexus-net which wraps both winrt-net and chome-net and is used the same way (JSPM, renaming in config file, etc...) as this module.

WinRT quirks

WinRT won't let your server receive localhost connections from other apps or programs.

Network communications using an IP loopback address cannot be used for interprocess communication (between two different apps) in a Windows Runtime app since this is restricted by network isolation. Network communication using an IP loopback address is allowed within an app within the same process for communication purposes.

For more info see this article How to enable loopback and troubleshoot network isolation

implementation

Some things are not (yet) implemented. Namelly

  • Socket.ref();
  • Socket.unref();
  • Socket._unrefTimer();
  • Socket.setEncoding();
  • Socket.setTimeout();
  • Socket.setNoDelay();
  • Socket.setKeepAlive();

Contribution

I'll be using this module in my projects and fixing bugs along the way but I'd really appreciate your help and will gladly accept issues, pull requests, or even someone being a full blown contributor

JSPM & Browserify

This project was built for and tested using JSPM.

I'm not using browserify nor do I know how to set up a project for it and currently I don't have enough time to look into it now. But again I'll be more than happy to accept pull requests

Building & Testing

The net module and all test files are written in ES6 modules using the import net from 'net'; syntax and has to be transpiled

gulp dev

This transpiles src/net.js to CommonJS format to lib/net.js but also into demo/net.js in SystemJS format (with all of the tes files in src/test/) for testing using JSPM.

Testing a WinRT app is a bit trickier since it's not that simple to run batch of automated test like Mocha. And the nature of sockets and networking throws unpredictability into the mix, making it even worse. I'm open to advices but for now testing looks like this.

  1. Pick a script file to run and define it in demo/run.js like so System.import('demo/test/client1.js');
  2. Run the demo app through Visual Studio
  3. Compare results with the real Node.JS by running
jspm run demo/run.js

Note: this runs the same script file you defined in demo/run.js but JSPM handles the System.import() module loading syntax and uses real Node net module whereas in the WinRT App the demo/net.js is loaded in place of the net.

Or you can simply run the file directly.

jspm run demo/test/server1.js

license

MIT. Copyright (c) Mike Kovařík