forked from mafintosh/turbo-net
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (18 loc) · 704 Bytes
/
index.js
File metadata and controls
24 lines (18 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const Server = require('./lib/server')
const Connection = require('./lib/connection')
exports.Server = Server
exports.Connection = Connection
exports.createServer = function (opts, onconnection) {
if (typeof opts === 'function') return exports.createServer(null, opts)
const server = new Server(opts)
if (onconnection) server.on('connection', onconnection)
return server
}
exports.connect = function (port, host, opts) {
if (typeof host !== 'string' && host) return exports.connect(port, null, host)
if (!opts) opts = {}
var connection = new Connection()
if (opts.allowHalfOpen) connection.allowHalfOpen = true
connection._connect(port, host || '127.0.0.1')
return connection
}