- I discovered that there were version problems with ejabberd and erlang.
- I created a new distribution and the mod_adhoc problem went away.
- I decided to keep using the ejabberd BOSH server.
Having resolved to use ejabberd's BOSH server for the time being I took a look into how Node.js does TCP servers. The good news is that node makes it pretty easy to create a TCP server. The bad news is that the stuff that I had already done for handling HTTP has to be thrown out. The so-so news is that there wasn't all that much to get rid of.
Originally, I was planning on having ECM do any buffering that was required for each request so that the server did not have to use space on it's side to do that. At this point, it seems like the simplest course of action is to dispense with that approach and just let ECM concentrate on multiplexing connections.
Buffering a complete HTTP POST should not be that hard, but it would mean having to wade through the various headers and the like as well as keeping track of whether you have already parsed the content length. Perhaps I will come back to that later, but for now I think I will skip it.
Simply setting up a TCP server is a pretty simple matter for node. Here is the code to setup a server to listen for connections send a quick hello style string and then close the connection:
var net = require('net')
var server = new net.createServer(processConnection);
server.listen(8280);
function processConnection(connection)
{
console.log("got connection");
connection.write("hi there\r\n");
connection.on ('end', function() {
console.log("connection closed");
});
connection.end();
}
When I connect using telnet to port 8280, I get the following result:
$ telnet localhost 8280
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hi there
Connection closed by foreign host.
On the server side I get the following:
$ node app.js
config = { server: { host: 'localhost', port: 6280 },
client: { port: 8280 },
misc: { prefixLength: 32 } }
now connected to localhost:6280
got connection
connection closed
So far, pretty straight forward stuff. The fun will start when I try to keep track who which connection a message is coming from and whatnot.
For next time:
- Modify ECM to create a new exchange for each connection.
- Change the connections from using requests and responses to using sockets.
No comments:
Post a Comment