How can i connect to asterisk in Node.js

user1968030

I want connect to asterisk via socket programming how can i do this? I know there are many module that we can use of these but i dont want use theme. I read this page and want to know How can i connect to asterisk in Node.js via socket programming ? This code is TCP Sample:

var net = require('net');

var HOST = '127.0.0.1';
var PORT = 6969;

// Create a server instance, and chain the listen function to it
// The function passed to net.createServer() becomes the event handler for the 'connection' event
// The sock object the callback function receives UNIQUE for each connection
net.createServer(function(sock) {

    // We have a connection - a socket object is assigned to the connection automatically
    console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);

    // Add a 'data' event handler to this instance of socket
    sock.on('data', function(data) {

        console.log('DATA ' + sock.remoteAddress + ': ' + data);
        // Write the data back to the socket, the client will receive it as data from the server
        sock.write('You said "' + data + '"');

    });

    // Add a 'close' event handler to this instance of socket
    sock.on('close', function(data) {
        console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
    });

}).listen(PORT, HOST);

console.log('Server listening on ' + HOST +':'+ PORT);
user1968030

Use this article: We can use socket programming in node.This sample code is for connect via TCP.

var net = require('net');
var port = 5038;
var host = "IP";
var username = "User";
var password = "Pass";
var CRLF = "\r\n";
var END = "\r\n\r\n";
var client = new net.Socket();

client.connect(port, host, function () {

    console.log('CONNECTED TO: ' + host + ':' + port);
    var obj = { Action: 'Login', Username: username, Secret: password};
    obj .ActionID =1;
    var socketData = generateSocketData(obj);
    console.log('DATA: ' + socketData);
    client.write(socketData, 'ascii');

});
generateSocketData = function(obj) {
    var str = '';
    for (var i in obj) {
       console.log('obj[i]:'+obj[i]);
        str += (i + ': ' + obj[i] + CRLF);
    }
    return str + CRLF;
};
client.on('data', function (data) {
    console.log('New Event Recived');
    console.log('******************************');
    console.log('DATA: ' + data);


});

client.on('close', function () {
    console.log('Connection closed');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i connect Luis to Node.js

From Dev

How can i connect to a meteor.js mongodb instance from a diffrent node.js proccess

From Dev

Asterisk, How can i play an audio file

From Dev

how can we connect sqlite using node.js?

From Dev

How can I install node.js?

From Dev

How can I make node js synchronize?

From Dev

How to use Asterisk ARI with socket.io & Node.js

From Dev

How can I check the version of asterisk I am running?

From Dev

How can I check the version of asterisk I am running?

From Dev

How can I connect an Android HTML/JS program to a LAN server?

From Dev

How can I get WindowsAzureActiveDirectoryBearerAuthenticationOptions to accept an audience with an asterisk

From Dev

How can i use asterisk(*) in command line arguments in groovy?

From Dev

Can't connect to a node js server in Android

From Dev

Can't connect to a node js server in Android

From Dev

Can Node JS connect to MongoDB and mySQL simultaneously?

From Dev

Freepbx can't connect to asterisk wrong password

From Dev

How can connect MySQL database + Node JS for React JS front end?

From Dev

how can I connect to database

From Dev

How can I detect the entry file in Node.js?

From Dev

How can I convert a string to a variable name in Node.js?

From Dev

How can I upsert multiple objects with MongoDB & Node.js?

From Dev

How can i upload an image to a node js server without a form?

From Dev

How can I update the protractor npm module in node.js?

From Dev

How can I purposefully crash my node.js server?

From Dev

How can I set a timeout for a zmq request in Node.js?

From Dev

How can I specify xhr request with node.js + cheerio?

From Dev

How can I make local changes to node.js library?

From Dev

How can i send a webcal request with node.js?

From Dev

How can I be careful installing node.js via apt?

Related Related

  1. 1

    How can i connect Luis to Node.js

  2. 2

    How can i connect to a meteor.js mongodb instance from a diffrent node.js proccess

  3. 3

    Asterisk, How can i play an audio file

  4. 4

    how can we connect sqlite using node.js?

  5. 5

    How can I install node.js?

  6. 6

    How can I make node js synchronize?

  7. 7

    How to use Asterisk ARI with socket.io & Node.js

  8. 8

    How can I check the version of asterisk I am running?

  9. 9

    How can I check the version of asterisk I am running?

  10. 10

    How can I connect an Android HTML/JS program to a LAN server?

  11. 11

    How can I get WindowsAzureActiveDirectoryBearerAuthenticationOptions to accept an audience with an asterisk

  12. 12

    How can i use asterisk(*) in command line arguments in groovy?

  13. 13

    Can't connect to a node js server in Android

  14. 14

    Can't connect to a node js server in Android

  15. 15

    Can Node JS connect to MongoDB and mySQL simultaneously?

  16. 16

    Freepbx can't connect to asterisk wrong password

  17. 17

    How can connect MySQL database + Node JS for React JS front end?

  18. 18

    how can I connect to database

  19. 19

    How can I detect the entry file in Node.js?

  20. 20

    How can I convert a string to a variable name in Node.js?

  21. 21

    How can I upsert multiple objects with MongoDB & Node.js?

  22. 22

    How can i upload an image to a node js server without a form?

  23. 23

    How can I update the protractor npm module in node.js?

  24. 24

    How can I purposefully crash my node.js server?

  25. 25

    How can I set a timeout for a zmq request in Node.js?

  26. 26

    How can I specify xhr request with node.js + cheerio?

  27. 27

    How can I make local changes to node.js library?

  28. 28

    How can i send a webcal request with node.js?

  29. 29

    How can I be careful installing node.js via apt?

HotTag

Archive