import FabricHubBase from 'msg-fabric-core'
import tcp from 'msg-fabric-core/esm/plugin-net-tcp'
// or: import { tcp } from 'msg-fabric-core/esm/plugin-net-all'
const FabricHub = FabricHubBase.plugin( tcp() )
const hub = FabricHub.create()
// client:
hub.connect('tcp://«host»:«port»')
hub.tcp.connect({ host, port })
// server:
hub.tcp.createServer()
.listen(port)
import FabricHubBase from 'msg-fabric-core'
import tls from 'msg-fabric-core/esm/plugin-net-tls'
// or: import { tls } from 'msg-fabric-core/esm/plugin-net-all'
const FabricHub = FabricHubBase.plugin( tls() )
const hub = FabricHub.create()
// client:
hub.connect('tls://«host»:«port»')
hub.tls.connect({ host, port })
// server:
hub.tls.createServer(tls_options)
.listen(port)
hub.tls.with_url_options({ca: certificate_authority})
import FabricHubBase from 'msg-fabric-core'
import direct_stream from 'msg-fabric-core/esm/plugin-net-direct'
// or: import { direct_stream } from 'msg-fabric-core/esm/plugin-net-all'
const FabricHub = FabricHubBase.plugin( direct_stream() )
const hub = FabricHub.create()
const hub_peer = FabricHub.create()
hub.direct_stream.connect(hub_peer)
Creates a TCP client connection and returns a Promise
for the channel
wrapping it. args
are passed to `require('net').createConnection(...args)
Creates a TCP server using require('net').createServer
.
A new channel is created for each new TCP client connection.
If provided, onPeer(channel)
or srv.emit(onPeer, channel)
is called.
Creates a TLS client connection and returns a Promise
for the channel
wrapping it. args
are passed to `require('net').createConnection(...args)
Creates a TLS server using require('tls').createServer
.
A new channel is created for each new TLS client connection.
If provided, onPeer(channel)
or srv.emit(onPeer, channel)
is called.
Uses hub.direct_stream.connectPair(peer)
and returns a Promise
for the outbound channel sending from hub
to peer
.
Uses hub.direct_stream.connectPair(peer)
and returns a Promise.all
over both channels.
Uses hub.direct_stream.createChanel()
to create a channel on hub
and on peer
for duplex communication.
Returns a list of two promises: the first sending from hub
to peer
, the second sending from peer
to hub
.
Creates and initializes a new channel using dispatch
function for transport.
Updates defaults connection options used when hub.connect('tcp://«host»:«port»')
(or 'tls://'
) is called.
An optional hook called when hub.connect('tcp://«host»:«port»')
(or 'tls://'
) is used.
Provide a function of the form (options, url) => options
to override.
Use the specified codec
if provided. If falsy, hub.stream_codec
instance is used.
Allows using a different P2P peering behavior for created channels.
If p2p is falsy, the shared hub.p2p
instance is used.