LearnBoost/socket.io — Issue #645: socket.send() callbacks don't work
Author: hjesbguhs
Created: 2011-11-15 14:47:35+00:00
State: open

When using `socket.send()` instead of `socket.emit()` the callbacks don't work.

client:

```javascript
socket.send('test',function(data){
...
});
```

server:

```javascript
socket.on('message',function(data,cb){
//cb is undefined
});
```

I got it working with these changes. However I'm not quite sure if it's a bug or you just shouldn't use .send with callbacks.

node (in `Socket.prototype.send`) replace:

```javascript
...
if (fn) {
packet.id = ++this.ackPackets;
packet.ack = true;
this.acks[packet.id] = fn;
}
...
```

with

```javascript
...
if ('function' == typeof fn) {
packet.id = ++this.ackPackets;
packet.ack = fn.length ? 'data' : true;
this.acks[packet.id] = fn;
}
...
```

browser (in `SocketNamespace.prototype.send`):

```javascript
...
if ('function' == typeof fn) {
packet.id = ++this.ackPackets;
packet.ack = true;
this.acks[packet.id] = fn;
}
...
```

with

```javascript
...
if ('function' == typeof fn) {
packet.id = ++this.ackPackets;
packet.ack = fn.length ? 'data' : true;
this.acks[packet.id] = fn;
}
...
```