Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.php
More file actions
Latest commit
34 lines (25 loc) · 887 Bytes
/
Copy pathserver.php
File metadata and controls
34 lines (25 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// nc localhost 4000
useReact\ExampleChatWithRandomStranger\AppInterface;
useReact\ExampleChatWithRandomStranger\LoggingApp;
useReact\ExampleChatWithRandomStranger\PairApp;
useReact\ExampleChatWithRandomStranger\TextApp;
require'vendor/autoload.php';
$logger = newMonolog\Logger('ExampleChatWithRandomStranger');
$logger->pushHandler(newMonolog\Handler\StreamHandler(STDOUT));
$app = newLoggingApp(
newTextApp(newPairApp()),
$logger
);
$loop = React\EventLoop\Factory::create();
$socket = newReact\Socket\Server($loop);
$i = 0;
$names = ['Alice', 'Bob', 'Carol', 'Dave', 'Erin', 'Frank', 'Eve',
'Mallory', 'Oscar', 'Peggy', 'Trent', 'Walter'];
$socket->on('connection', function ($conn) use (&$i, $names, $app) {
$conn->id = isset($names[$i]) ? $names[$i] : $i;
$app->connect($conn);
$i++;
});
$socket->listen(4000);
$loop->run();