Skip to content

XSocketsNodeJs Test

Uffe Björklund edited this page Jun 16, 2015 · 17 revisions

TODO: Change to NDC protocol and add NDC protocol tutorial

###Pre-Req

Code

Create a new file with nano sockettest.js and write a simple test. Replace the IP with the IP of your development machine.

var xsockets = require('xsockets.net');

var c = new xsockets.TcpClient('192.168.254.154', 4502, ['generic']);
var g = c.controller('generic');
g.on('foo', function(d) {
    console.log('foo',d);
    g.send('bar','hello from nodejs');
});

g.onopen = function(ci) {
    console.log('connected controller generic');
    g.send('foo', {text:'bar'});
}

c.onconnected = function(d) {
    console.log('connected', d);
}
c.open();

###Test

Run the test with node sockettest.js

Then open up Putty and connect to the same sever as the script, this would be the 192.168.x.x of your machine. Then type in PuttyProtocol in Putty to do a handshake. Then send a message to nodejs by typing generic|foo|hello from putty

next

Clone this wiki locally