noflo: how to add inport and outport to a graph programatically

88 views
Skip to first unread message

Santosh Kumar

unread,
Nov 13, 2017, 6:06:39 PM11/13/17
to Flow Based Programming
Hi,

I have realized that any noflo network needs inPorts and outPorts for it to function. Those are the places from where IIPs are pushed in and result retrieved. 

The documentation has example for it---- in case we use a fbp or jason file but not if graph is created programatically in JS. The Canadianness example has it in fbp here https://github.com/noflo/canadianness/blob/master/graphs/Canadianness.fbp :

INPORT=SplitContent.IN:CONTENT

OUTPORT=Emotion.EMOTION:EMOTION


I could not find any example to establish such connection using JavaScript code. I inspected the graph object but could not locate any function for this purpose. I just have a forwarder node in my graph and want to send IIP to it and extract the result. Please see the comments in the code below:

var graph = noflo.graph.createGraph('testgraph');
graph.addNode('Forwarder Node','Forwarder');
//Here I need to connect forwarder component to
//inPort and outPort but could not find anything in Doc


noflo.createNetwork(graph, function(err,network){

if(err){
throw err;
}

const inp = noflo.internalSocket.createSocket();
const outp = noflo.internalSocket.createSocket();
//Next comes the code for attaching the sockets
//but inPorts and outPorts are not defined as
//I have not connected the forwarder node for input and output
network.inPorts.arbitraryInput.attach(inp) ;
network.outPorts.arbitraryOutput.attach(outp);

network.connect(function(conerr){
if(conerr){
throw conerr;
}
network.start(function(){
console.log('Network started');
//send IIP
});
});

},true);




Please let me know how to do it?

Thanks,
Santosh

Henri Bergius

unread,
Nov 14, 2017, 5:15:51 AM11/14/17
to flow-based-...@googlegroups.com
Hi,

On Tue, 14 Nov 2017 at 01:09 Santosh Kumar <lsantos...@gmail.com> wrote:
I have realized that any noflo network needs inPorts and outPorts for it to function. Those are the places from where IIPs are pushed in and result retrieved. 

Well, not quite. It is perfectly fine to have a network that doesn't expose any port. That is the way you often build your "main" graph in standalone NoFlo programs.

But of course exported ports are crucial if you want to use the network as a "component" somewhere.
 
I could not find any example to establish such connection using JavaScript code. I inspected the graph object but could not locate any function for this purpose. I just have a forwarder node in my graph and want to send IIP to it and extract the result.

The Graph implementation was extracted out of NoFlo at one point so that it could be used also in other JavaScript FBP-esque systems:

Here are the relevant methods for exporting ports:

Those methods are what NoFlo actually uses when you load a FBP or JSON graph.
 
Santosh

/Henri 

Santosh Kumar

unread,
Nov 14, 2017, 9:41:02 PM11/14/17
to flow-based-...@googlegroups.com
Thanks, Got the first flow running. Now I need to get graph and ui working along with noflo.

Your replies have been most useful.





--
You received this message because you are subscribed to a topic in the Google Groups "Flow Based Programming" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flow-based-programming/9aGBuCCsbjw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flow-based-programming+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages