igorw/SocketServer — pull request #9 by cboden (2012-04-24 14:54:06+00:00)
Title: [WIP] Method overloading on Connection

This allows extensibility on the Connection object. Different Socket implementation (stream, libevent, etc) can push their own write/close methods on Connections.

Listeners can intercept event data and encode/frame outgoing messages.

```php
on('connect', function ($conn) use (&$i) {
$i++;

$conn->write("What is your name?\n");

$conn->on('before.write', function(&$data) use (&$i) {
$data = "Tell connection {$i}: {$data}";
});

$conn->on('data', function ($data) use ($conn, &$i) {
$data = trim($data);
$conn->write("Hello {$data}!\n");
$conn->close();
});
});

$server->run();
```

telnet localhost 8000
Chris

The implementation is a bit hacky - but what are your thoughts on the concept?