netly
v0.1.4
Published
Make working with net dead simple and slicker
Downloads
5
Maintainers
Readme
netly
Make working with NodeJS net dead simple and slicker.
Usage
var net = require('netly');
// server
var server = net.bind({ port: 7101, host: '127.0.0.1' });
server.on('connection', function (socket) {
console.log('incoming connection');
});
// client
var conn = net.connect({ port: 7101, host: '127.0.0.1' });
Installation
$ npm install netly
API
net.bind(port, [host], [callback])
Begin accepting connections on the specified port
and host
.
This method is the equivalent of using createServer
and listen
toguether.
These are all supported arguments:
// port
var server = net.bind(7101, fn);
// "host:port"
var server = net.bind('190.168.1.1:7101', fn);
// { host, port }
var server = net.bind({ host: '190.168.1.1', port: 7101 }, fn);
// { address, port }
var server = net.bind({ address: '190.168.1.1', port: 7101 }, fn);
net.connect(port, [host], [callback])
Create a tcp connection to the address specified by obj
.
Optionally pass a listener
fn to be called when the connection has been
established.
var net = require('netly');
// port
var con = connect(7101, fn);
// "host:port"
var conn = net.connect('190.168.1.1:7101', fn);
// { host, port }
var conn = net.connect({ host: '190.168.1.1', port: 7101 }, fn);
// { address, port }
var conn = net.connect({ address: '190.168.1.1', port: 7101 }, fn);
Run Test
$ make test
License
(The MIT License)
Copyright (c) 2014 Jonathan Brumley <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.