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

For review: some more sample chat fixes #29

Merged
merged 4 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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