[Pharo-project] little challenge for sven and us

Norbert Hartl norbert at hartl.name
Thu Jun 30 11:37:06 EDT 2011


Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:

>>> Hi guys
>>> 
>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>> 
>> What does it mean?
> 
> in Pharo.. how do you have the same: 

It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.

Is that what you asked?

Norbert

> 
>>> 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
>> 
>> 
> 
> 





More information about the Pharo-dev mailing list