Hoa central
Client.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Console;
40 use Hoa\Socket;
41 use Hoa\Websocket;
42 
52 {
58  protected $options = [
59  ['server', Console\GetOption::REQUIRED_ARGUMENT, 's'],
60  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
61  ['help', Console\GetOption::NO_ARGUMENT, '?']
62  ];
63 
64 
65 
71  public function main()
72  {
73  $server = '127.0.0.1:8889';
74 
75  while (false !== $c = $this->getOption($v)) {
76  switch ($c) {
77  case 's':
78  $server = $v;
79 
80  break;
81 
82  case 'h':
83  case '?':
84  return $this->usage();
85 
86  case '__ambiguous':
87  $this->resolveOptionAmbiguity($v);
88 
89  break;
90  }
91  }
92 
93 
94  $readline = new Console\Readline();
95  $client = new Websocket\Client(
96  new Socket\Client('tcp://' . $server)
97  );
98  $client->setHost('localhost');
99  $client->connect();
100 
101  do {
102  $line = $readline->readLine('> ');
103 
104  if (false === $line || 'quit' === $line) {
105  break;
106  }
107 
108  $client->send($line);
109  } while (true);
110 
111  $client->close();
112 
113  return;
114  }
115 
121  public function usage()
122  {
123  echo
124  'Usage : websocket:client <options>', "\n",
125  'Options :', "\n",
126  $this->makeUsageOptionsList([
127  's' => 'Server URI (default: 127.0.0.1:8889).',
128  'help' => 'This help.'
129  ]), "\n";
130 
131  return;
132  }
133 }
134 
135 __halt_compiler();
136 Basic WebSocket client.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190