diff --git a/README.md b/README.md index 3b26232..db6b890 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,12 @@ The folder called `test` contains a number of Mocha tests. 1. Run `npm test` to execute a series of tests (all the `fbptestxx.js` tests in sequence). 2. Alternatively, you can directly execute `node.exe node_modules/mocha/bin/mocha --recursive --require test/test_helper.js` in case you need to adjust the path to Node's binary or pass further parameters to Mocha. +# Testing Sample HTTP Server + +Run `node examples/httpserver/fbphttpserver.js`, which is a simple HTTP server which is similar to the one in the sample at: http://blog.modulus.io/build-your-first-http-server-in-nodejs + +NOTE: The HTTP server components are currently all custom components, based on the components used in the simple web socket chat server described below. + # Testing Simple Web Socket Chat Server 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. diff --git a/components/collate.js b/components/collate.js index 40054d1..87b78d6 100644 --- a/components/collate.js +++ b/components/collate.js @@ -6,9 +6,9 @@ module.exports = function collate() { var outport = this.openOutputPort('OUT'); var ctlfieldsP = ctlfields.receive(); + var fields = ctlfieldsP.contents.split(',').map(function(str) { return parseInt(str); }); this.dropIP(ctlfieldsP); - var fields = ctlfieldsP.contents.split(',').map(function(str) { return parseInt(str); }); var totalFieldLength = fields.reduce(function(acc, n) { return acc + n; }, 0); var portCount = inportArray.length; @@ -40,4 +40,4 @@ module.exports = function collate() { portCount--; } } -} \ No newline at end of file +} diff --git a/components/httpserver.js b/components/httpserver.js new file mode 100644 index 0000000..1007d10 --- /dev/null +++ b/components/httpserver.js @@ -0,0 +1,64 @@ +'use strict'; + +var IP = require('../core/IP') + , http = require('http'); + +module.exports = function httpserver(runtime) { + var inport = this.openInputPort('PORTNO'); + var outport = this.openOutputPort('OUT'); + + var ip = inport.receive(); + var portno = ip.contents; + var server = http.createServer(handleServerRequest); + + runtime.runAsyncCallback(genListenFun(runtime, server, portno, this)); + + while (true) { + var result = runtime.runAsyncCallback(genReceiveFun(runtime, server, portno, this)); + + for (var i=0; i