Node.js sokets

NodeBB Development
  • hi there, i need to create a soket that can get information from an other soket. my node server is hosted and i want to create in my localhost a soket that can connect to that server and give me some text information.
    can anyone help me with this?

  • @ahmed_commando It sounds like you will probably want to look into NodeBB plugin development. A NodeBB plugin can either hook into the SocketIO the NodeBB server is handling for reading or it can generate its own content for sending.

  • thank you for helping, but i can't found the plugin. PS : im new with node.js so plz help with a snippet.

  • I don't know of any plugin that is already built to do what you want. Like most of the rest of us, you will likely have to write some Node JavaScript to create the plugin to suit your needs. I don't have the time to write custom code for free, although if it is worth money to you, the NodeBB development team may be interested in consulting for you.
    Now that I re-read what you originally asked, I'm curious if you actually need "Sockets" (as in SocketIO, which is server-initiated TCP/IP connection to a browser) or if APIs on both the hosted NodeBB server and the localhost server would do this better.
    Either way, if you choose to go the NodeBB plugin route, you will need to know which Hooks are available. A "hook" is an event that your plugin subscribes to. When that event happens in the core NodeBB server, it will call the function in your plugin which subscribes to the event.


Suggested Topics


  • No footer.js in v16.1.x?

    NodeBB Development
    5
    0 Votes
    5 Posts
    388 Views

    EDIT:

    @baris error is gone / fixed. Thank you!

  • 0 Votes
    4 Posts
    2k Views

    Nice way to debug. I am still using console.log() 🙂 I guss my stuff is to simple

  • nodebb.min.js not updated

    NodeBB Development
    8
    0 Votes
    8 Posts
    3k Views

    @PitaJ Thanks you! nodebb.min.js updated successfully.

  • 0 Votes
    1 Posts
    2k Views

    Well, I have this issue that I need to do following things:
    1.Mongo Find
    2. Foreach
    3. MongoFind
    4 one more Foreach.

    because of asynchronaus mongo calls it is difficult to get proper result, however process.nextTick should handle this problem and still I have problem:

    function find(dbComm) {

    dbComm.forEach(function (current) { id= parseFloat(current.ID); db.anotherCollection.find({ ID: id}, function (error, result) { result.forEach(function (rank) { if (parseFloat(result.ID) == parseFloat(current.ID)) { rank.rank = 'Some calculations'; } }); }); });

    }

    app.get('/someparams', function (req, res) {

    db.collection.find().sort({ "rank": order }).skip(pagenumber).limit(5, function (err, result) { process.nextTick(function () { find(result, function () { }) }); process.nextTick(function () { res.send(result); }); });

    And on client side I should recive an array where the rank equals 'Some Calculations'
    but unfortunetly it is not...
    However...! If I add setTimeout(function(){}) before res.send(result) (and res.send(result) will be placed inside setTimeout) it actually does work and on client side I recive data with "Some Calculations" but it is just timeout and it fails sometimes and client dont recive "Some Calculations"
    if I put process.nextTick instead of setTimeout it doesnt work and "Some calc..." are not sent.

    Something is beeing done eralier then it should (probably in forEach in find() function)
    and my question is how to deal with it? maybe I should put process.nextTick in different function ?

  • 0 Votes
    8 Posts
    4k Views

    @julian Thanks, now it's no problem : )