Completed
Push — master ( dce25d...9db7be )
by Dimas
09:29 queued 12s
created

echoServer::connected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
nc 1
nop 1
dl 0
loc 2
c 1
b 0
f 0
cc 1
rs 10
1
#!/usr/bin/env php
2
<?php
3
4
require_once './websockets.php';
5
6
class echoServer extends WebSocketServer
7
{
8
  public function __construct($addr, $port, $bufferLength)
9
  {
10
    parent::__construct($addr, $port, $bufferLength);
11
    $this->userClass = 'MyUser';
12
  }
13
14
  //protected $maxBufferSize = 1048576; //1MB... overkill for an echo server, but potentially plausible for other applications.
15
16
  protected function process($user, $message)
17
  {
18
    $this->send($user, $message);
19
  }
20
21
  protected function connected($user)
22
  {
23
    // Do nothing: This is just an echo server, there's no need to track the user.
24
  // However, if we did care about the users, we would probably have a cookie to
25
  // parse at this step, would be looking them up in permanent storage, etc.
26
  }
27
28
  protected function closed($user)
29
  {
30
    // Do nothing: This is where cleanup would go, in case the user had any sort of
31
  // open files or other objects associated with them.  This runs after the socket
32
  // has been closed, so there is no need to clean up the socket itself here.
33
  }
34
}
35
36
$echo = new echoServer('0.0.0.0', '9000', 2048);
37
38
try {
39
  $echo->run();
40
} catch (Exception $e) {
41
  $echo->stdout($e->getMessage());
42
}
43