deepstream from scratch

Aug 9, 05:15 AM

2016-08-09

UPDATE: 2017-02-03 – firewall:
firewall-cmd —zone=public —add-port=6020/tcp —permanent ;
firewall-cmd —reload

ran on amazon ec2-instance

be SURE to get the IP numbers before starting – notice that amazon has an internal and external number which may be different

1) open ports via amazon “security groups” under “network and security” and open ports (in this example, ports 9020 and 9021)

2) PING – create a new “inbound rule” by picking the “ALL ICMP” dropdown and the “Anywhere” dropdown.

sudo -i ; ## go into super-user mode (sort of) on amazon or wherever sudo is required

  1. install & start deepstream
    wget https://bintray.com/deepstreamio/rpm/rpm -O /etc/yum.repos.d/bintray-deepstreamio-rpm.repo ;
    yum —assumeyes install deepstream.io ;
    deepstream start &

  1. install node:
    curl —silent —location https://rpm.nodesource.com/setup_6.x | bash – ;
    yum —assumeyes install nodejs ;

  1. run a deepstream server
    npm init; ### create a package.json file
    npm install deepstream.io —save ; ## might take a little while
    npm install deepstream.io-client-js —save ; ## dont forget

// OPTIONAL – create a little script to talk to our server. this is really
// a client, but it just so happens to be running on the server
// however, it behaves just like a client would!
// the only difference is the internal IP and the different port number

cat < client-on-server.js ;
var deepstream = require(‘deepstream.io-client-js’);
ds = deepstream( ’172.30.0.111:9021’ ).login(); // must match the host IP number in the server // port has to match tcpPort number in the server
record = ds.record.getRecord( ‘clientRecord’ );
record.set(‘clientField’, ‘test from the node client running on the server! ‘);
record.subscribe (‘clientField’ , function (value) { console.log(‘subscribed value: ‘ + value);
});
END

// lastly, a browser script !


optionally: ln -s ./node_modules/deepstream.io-client-js/dist/deepstream.min.js ; ## create a pointer to our deepstream.min.js file and use:

####cat < server.js ; ## NOT NEEDED !
####// deepstream server:
####var DeepstreamServer = require(‘deepstream.io’);
####var server = new DeepstreamServer();
####server.set(‘host’, ’172.30.0.111’); // use the I-N-T-E-R-N-A-L IP number !
####server.set (‘port’, 9020 );
####server.set (‘tcpPort’, 9021 );
####// this is the default, but its a nice reminder
####server.start();
####END
####
####node server.js & ## our new little deepstream server is now running in the background

  1. NO LONGER NEEDED !

==============================================
==============================================
success !

DS client-server listener (2016-08-11)

// newServer.js
var deepstream = require(‘deepstream.io-client-js’);
var util = require(‘util’);
var dateFormat = require(‘dateformat’);

ds = deepstream( ’172.30.0.114:9021’ ).login();
ds.record.listen(’^stock/.*’, function (recordName, isSubscribed) { console.log(‘recordName: ‘ + recordName) ; console.log(‘isSubscribed?: ‘ + isSubscribed) ; console.log(‘get client record:’); ds.record.getRecord( recordName ).get (‘stockField’ ); ds.record.getRecord( recordName ).set (‘stockField’ , ‘newServer setting this value ! ! !’ ); ds.record.getRecord( recordName ).subscribe (function (value) { console.log(’ newServer.js — subscribed value: ‘ + util.inspect(value)); var now = new Date(); ds.record.getRecord( recordName).set (‘result’ , ‘newServer is responding to you at ‘ + dateFormat(now, “dddd, mmmm dS, yyyy, h:MM:ss TT”) ); });
});

//newClient.js ( client test but runs on server AND MAY BE TOTALLY UNNECESSARY)
var deepstream = require(‘deepstream.io-client-js’);
var util = require(‘util’);

var recordName = ‘stock/mark’ ;

ds = deepstream( ’172.30.0.114:9021’ ).login();
ds.record.getRecord( recordName ).set(‘stockField’, ‘newClient is setting this value !! ‘);
ds.record.getRecord( recordName ).get(‘stockField’ );
ds.record.getRecord( recordName ).subscribe (function (value) { console.log(‘stock/mark — subscribed value: ‘ + util.inspect(value)); ds.record.getRecord( recordName ).get( );
});

// webpage one:



newtest.html

Mark Edwards

,

---

Commenting is closed for this article.

---