visionmedia/axon — pull request #10 by gjohnson (2012-08-03 16:51:41+00:00)
Title: naming stuff, multipart integration, first stab at socket/queue cleanup

### Naming stuff and multipart integration

This is just some changes we have been talking about (Parser/Message), etc. It is now integrated into the sockets. I made a few of those other changes related to buffers you were talking about, etc.

### First stab at socket/queue cleanup

I moved everything to `Socket` and now Queue simply queues messages. The two smallest changes I made probably had the most drastic effect on everything... Instead of `Sock` having a single "sock" instance, I actually have `connect()` create sockets and push them onto the `socks` array, just like `bind()` does with its connected clients. I switched `bind()` from emitting a `connection` event to emitting a `connect` event.

With those changes, now the sockets have no idea if they are client or server, which removed a nice bit of boiler plate code. Now any socket can trully be the "server" or the "client".

It also allows high level sockets to not have to inherit from Queue, for example I moved `PubSocket` to just extend `Socket` since it simply pumps data out in batches.

Lastly, it also allows sockets to have multiple peers and have thier messages delegated through the same "message event".

```javascript
// many pushers

var pusher1 = ss.socket('push');
var pusher2 = ss.socket('push');
var pusher3 = ss.socket('push');

pusher1.bind(3000);
pusher2.bind(3001);
pusher3.bind(3002);

pusher1.send('hey');
pusher2.send('hey');
pusher3.send('hey');

// one puller that connects to many pushers

var pull = ss.socket('pull');
pull.connect(3000);
pull.connect(3001);
pull.connect(3002);

// single message "channel"

pull.on('message', function(msg){

});
```