That's not really a challenge ;-)
Excellent I like to hear that :) Now we should add it on the web somewhere because this is the second lesson. We are not really good at communication. Stef
The second example is too simple to be useful, but this would be the Zn equivalent:
(ZnServer defaultOn: 1337) logToTranscript; delegate: (ZnValueDelegate with: [ :request | ZnResponse ok: (ZnEntity text: 'Hello World!') ]); start.
ZnClient get: 'http://localhost:1337'.
(ZnServer defaultOn: 1337) logToTranscript; delegate: (ZnValueDelegate with: [ :request | ZnResponse ok: (ZnEntity with: request contents) ]); start.
ZnClient post: 'http://localhost:1337' data: (ZnEntity text: 'Echo').
ZnServer stopDefault.
Smalltalk is a beautiful language, isn't it ?
Sven
PS: the delegate object has to respond to #handleRequest:. In earlier versions, it was a block, now ZnValueDelegate translates #handleRequest: to #value:. I thought that was clearer. For publicity reasons, maybe I could add a #delegateBlock: convencience accessor.
On 30 Jun 2011, at 17:07, Stéphane Ducasse wrote:
Hi guys
apparently people get excited by nodeJS and I would like to know the equivalence of
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res .end('Hello World\n'); }).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/'); To run the server, put the code into a file example.js and execute it with the node program:
% node example.js Server running at http://127.0.0.1:1337/
Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
var net = require('net'); var server = net.createServer(function (socket) { socket.write("Echo server\r\n"); socket.pipe(socket); });
server.listen(1337, "127.0.0.1");
we should communicate better :)
Stef