Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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!
jspm install npm:winrt-net
winrt-net
to net
in your SystemJS/JSPM config fileJSPM 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.
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:winrt-net@1.0.0",
"events": "github:jspm/nodelibs-events@0.2.0-alpha",
"process": "github:jspm/nodelibs-process@0.2.0-alpha",
...
you change the name like so
map: {
"net": "npm:winrt-net@1.0.0",
...
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)
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
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 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
Some things are not (yet) implemented. Namelly
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
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
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.
demo/run.js
like so System.import('demo/test/client1.js');
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
MIT. Copyright (c) Mike Kovařík
FAQs
WinRT (Windows App) wrapper for node net module
We found that winrt-net demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.