The Network API

Plugins often want to interact with files, processes and network within the user's workspace. Because all Cloud9 plugins run in the browser and there is a network between the browser and the user's workspace we looked for an API that would work asynchronously. The Node.js APIs were an obvious match and so we based our Filesystem (fs), Process (proc) and Network (net) APIs on Node's fs, child_process and net modules.

Getting a reference to the plugin

The following examples show how to gain access to the net APIs.

First, make sure to add "net" to your list of plugins you depend on like so:

main.consumes = ["Plugin", "net"];

And then get a reference to the plugin in the main function:

function main(options, imports, register) {
    var net = imports.net;

Network

For a complete reference to all the methods and events of the net plugin check out the net api reference.

The following table lists of all the methods supported by the net plugin.

connectConnects a regular socket to a port in the workspace.

The following example show the most common use cases connecting to a port on the 'local' workspace machine.

Connecting to a locally running HTTP server and getting the index page

net.connect(8080, {}, function(err, stream) {
    if (err) return console.error(err);

    stream.on("data", function(chunk) {
        console.log(chunk);
    });
    stream.write("GET /");
});