File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 77
88// Connects to the websocket endpoint in demo.php provided with Aerys (https://github.com/amphp/aerys).
99Amp \Loop::run (function () {
10- /** @var \Amp\ Websocket\Connection $connection */
10+ /** @var Websocket\Connection $connection */
1111 $ connection = yield Websocket \connect ('ws://localhost:1337/ws ' );
1212 yield $ connection ->send ('Hello! ' );
1313
1414 $ i = 0 ;
1515
16+ /** @var Websocket\Message $message */
1617 while ($ message = yield $ connection ->receive ()) {
1718 $ payload = yield $ message ->buffer ();
1819
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ require dirname (__DIR__ ) . '/vendor/autoload.php ' ;
4+
5+ use Amp \Delayed ;
6+ use Amp \Websocket ;
7+
8+ Amp \Loop::run (function () {
9+ /** @var Websocket\Connection $connection */
10+ $ connection = yield Websocket \connect ('ws://demos.kaazing.com/echo ' );
11+ yield $ connection ->send ('Hello! ' );
12+
13+ $ i = 0 ;
14+
15+ /** @var Websocket\Message $message */
16+ while ($ message = yield $ connection ->receive ()) {
17+ $ payload = yield $ message ->buffer ();
18+
19+ printf ("Received: %s \n" , $ payload );
20+
21+ if ($ payload === 'Goodbye! ' ) {
22+ $ connection ->close ();
23+ break ;
24+ }
25+
26+ yield new Delayed (1000 );
27+
28+ if ($ i < 3 ) {
29+ yield $ connection ->send ('Ping: ' . ++$ i );
30+ } else {
31+ yield $ connection ->send ('Goodbye! ' );
32+ }
33+ }
34+ });
You can’t perform that action at this time.
0 commit comments