GithubHelp home page GithubHelp logo

Problem WebSocket about core HOT 7 OPEN

c9 avatar c9 commented on July 30, 2024
Problem WebSocket

from core.

Comments (7)

javruben avatar javruben commented on July 30, 2024

Could you paste the full code of your plugin (first to last line)?

Thanks.

On Mar 20, 2015, at 9:52 AM, alessioguglielmo [email protected] wrote:

I wrote a plugin (and put it in ~/.c9/plugin/plugin-name) with following code:

var WebSocket = require('ws')
, ws = new WebSocket('ws://mylocalipaddress:8090/');
ws.on('open', function() {
ws.send('something');
});
ws.on('message', function(message) {
console.log('received: %s', message);
});
On localhost I have a server listening on port 8090

var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8090});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
When I try to load the IDE at

http://localhost:8186/ide.html?sdk=1?debug=2

It loads only IDE but not the plugin and my server doesn't receive any data.

If I try the same code in a client loaded in a different container it works perfectly.

Thanks


Reply to this email directly or view it on GitHub #41.

from core.

alessioguglielmo avatar alessioguglielmo commented on July 30, 2024
define(function(require, exports, module) {
    main.consumes = [
        "Plugin", "commands", "ui", "util", "Dialog", "dialog.alert", "tabManager"
    ];
    main.provides = ["example1"];
    return main;

    function main(options, imports, register) {
          var Plugin = imports.Plugin;
          var commands = imports.commands;
          var ui = imports.ui;
          var util = imports.util;

        /***** Initialization *****/

        var plugin = new Plugin("Ajax.org", main.consumes);
        var emit = plugin.getEmitter();
        var api  = plugin.setAPIKey(options.apikey);

        var loaded = false;
        function load() {
            if (loaded) return false;
            loaded = true;                      

        var WebSocket = require('ws')
            , ws = new WebSocket('ws://172.17.2.119:8090/');
        WebSocket.on('open', function() {
            WebSocket.send('something');
        });
        WebSocket.on('message', function(message) {
            console.log('received: %s', message);
        });

            // Test use of the API
            // api.setPersistentData("user", { example: 123 }, function(err){
            //     api.getPersistentData("user", function(err, data){
            //         console.error(data.example === 123);
            //     });
            // });

            // Test loading relative content
            console.error(require("text!./test.html"));

            // Test dependencies
            console.error(commands, options.color);
        }

        /***** Methods *****/

        /***** Lifecycle *****/

        plugin.on("load", function() {
            load();
        });
        plugin.on("enable", function() {

        });
        plugin.on("disable", function() {

        });
        plugin.on("unload", function() {
            loaded = false;
        });

        /***** Register and define API *****/

        /**
         * 
         **/
        plugin.freezePublicAPI({
            _events: [
                /**
                 * @event draw
                 */
                "draw"
            ]
        });

        register("", {
            example1: plugin
        });
    }
});

from core.

javruben avatar javruben commented on July 30, 2024

The plugin looks good, although I don't fully understand why you set an outside IP address in your plugin.

It loads only IDE but not the plugin and my server doesn't receive any data.

How do you know the plugin isn't loaded? Could you test by setting a console.log in your load() function?

If you check the network tab of the browser's console. Do you see the websocket trying to connect?

from core.

alessioguglielmo avatar alessioguglielmo commented on July 30, 2024

I have c9 on a container and a WebSocket server in a different docker
container. I suppose that plugin isn't loaded because in firebug I can't
find trace about console.log (when I added it) and also alert messages
aren't displayed at all. Likely it found some error and blocks js
execution... I will try to re-implement the scenario and check the network
tab.

2015-03-21 19:53 GMT+01:00 Ruben Daniels [email protected]:

The plugin looks good, although I don't fully understand why you set an
outside IP address in your plugin.

It loads only IDE but not the plugin and my server doesn't receive any
data.
How do you know the plugin isn't loaded? Could you test by setting a
console.log in your load() function?

If you check the network tab of the browser's console. Do you see the
websocket trying to connect?


Reply to this email directly or view it on GitHub
#41 (comment).

from core.

alessioguglielmo avatar alessioguglielmo commented on July 30, 2024

Nope. In the network tab my websocket is absent...

from core.

alessioguglielmo avatar alessioguglielmo commented on July 30, 2024

I've checked package.json file. Should I add something to it?

{
  "name": "c9.ide.example",
  "description": "Cloud9 Custom Example Plugin",
  "version": "1.12.16",
  "author": "Ajax.org B.V. <[email protected]>",
  "contributors": [
    {
      "name": "Ruben Daniels",
      "email": "[email protected]"
    }
  ],
  "repository": {
    "type": "git",
    "url": "http://github.com/javruben/example.git"
  },
  "plugins": {
    "example": {}
  },
  "categories": [
    "example"
  ],
  "licenses": []
}

I tried to use other "common node.js API" such as path or querystring (that have slightly different sintax) that I've seen in the documentation and they work perfectly. The problem is with "ws"

from core.

alessioguglielmo avatar alessioguglielmo commented on July 30, 2024

Worked around the problem using different way, passing data through fs, although the original problem I have quoted persists.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.