Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29 from brodybits/cb-more-wschat-example-fixes
Browse files Browse the repository at this point in the history
For review: some more sample chat fixes
  • Loading branch information
jpaulm committed Aug 26, 2015
2 parents 288382f + cf002f5 commit 185bc94
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The folder called `test` contains a number of Mocha tests.

# Testing Simple Web Socket Chat Server

Run `node examples/websocketchat/fbptestwschat.js`, which is a simple web socket chat server. It responds to any request by broadcasting it to all connected clients.
Run `node examples/websocketchat/fbptestwschat.js`, which is a simple web socket chat server which responds to any request by broadcasting it to all connected clients. It is similar to the chat sample at: http://socket.io/get-started/chat/ except for serving the client HTML.

`examples/websocketchat/index.html` is intended as a simple chat client for testing with `fbptestwschat.js`. If Firefox doesn't work for you, Chrome and Safari will work.

Expand Down
6 changes: 5 additions & 1 deletion components/wsrecv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ var IP = require('../core/IP')

module.exports = function wsrecv(runtime) {
var inport = this.openInputPort('PORTNO');
var outport = this.openOutputPort('OUT');
var wssout = this.openOutputPort('WSSOUT');

var ip = inport.receive();
var portno = ip.contents;
var wss = new WebSocketServer({ port: portno });
wssout.send(this.createIP(wss));

var ws = null;
while (true) {
var result = runtime.runAsyncCallback(genWsReceiveFun(runtime, wss, ws, this));
Expand All @@ -18,7 +23,6 @@ module.exports = function wsrecv(runtime) {
}

console.log(result);
var outport = this.openOutputPort('OUT');
outport.send(this.createIPBracket(IP.OPEN));
outport.send(this.createIP(result[0]));
outport.send(this.createIP(result[1]));
Expand Down
5 changes: 3 additions & 2 deletions examples/websocketchat/fbptestwschat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ var fbp = require('../..');
// --- define network ---
var network = new fbp.Network();

var receiver = network.defProc(require('./wschatrecv'));
var receiver = network.defProc(require('../../components/wsrecv'));
var simproc = network.defProc(require('./wssimproc'));
var send = network.defProc(require('./wschatsend'));
var send = network.defProc(require('./wsbroadcast'));

network.initialize(receiver, 'PORTNO', '9003');
network.connect(receiver, 'WSSOUT', send, 'WSSIN', 6);
network.connect(receiver, 'OUT', simproc, 'IN', 6);
network.connect(simproc, 'OUT', send, 'IN', 6);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

var IP = require('../../core/IP');

module.exports = function wschatresp() {
module.exports = function wsbroadcast() {
var ip;
var inport = this.openInputPort('IN');
var wssin = this.openInputPort('WSSIN');

ip = wssin.receive(); // shd be wss
var wss = ip.contents;

while (true) {
ip = inport.receive(); // shd be open bracket
if (ip === null) {
break;
}
//console.log(ip);
this.dropIP(ip);
ip = inport.receive(); // shd be wss
//console.log(ip);
var wss = ip.contents;
this.dropIP(ip);
ip = inport.receive(); // shd be orig connection
//console.log(ip);
var ws = ip.contents;
Expand Down
48 changes: 0 additions & 48 deletions examples/websocketchat/wschatrecv.js

This file was deleted.

2 changes: 0 additions & 2 deletions examples/websocketchat/wssimproc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module.exports = function wssimproc() {
}
// not null, so this IP was open bracket
outport.send(ip); //send it on
ip = inport.receive(); // wss object
outport.send(ip); // send it on
ip = inport.receive(); // connection
outport.send(ip); // send it on
ip = inport.receive(); // data IP - drop and emit modified message
Expand Down

0 comments on commit 185bc94

Please sign in to comment.