Created
July 9, 2014 09:58
-
-
Save thehawk970/c9326f00c913eff5f961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
try { | |
$w = new Hoa\Socket\Client('tcp://127.0.0.1:8889'); | |
$client = new Hoa\Websocket\Client($w); | |
$client->on('open', function ( Hoa\Core\Event\Bucket $bucket ) { | |
echo 'Websocket opened!'; | |
return; | |
}); | |
$client->on('message', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo 'received message: ', $data['message'], "\n"; | |
return; | |
}); | |
$client->on('close', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo 'closure code: ', $data['code'], "\n"; | |
echo 'closure reason: ', $data['reason'], "\n"; | |
return; | |
}); | |
$client->on('error', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo 'Websocket error : ', $data['exception'], "\n"; | |
return; | |
}); | |
$client->setHost("127.0.0.1"); | |
$client->connect(); | |
$client->send('foobar'); | |
echo $client->receive(); | |
$client->close(); | |
} | |
catch(Exception $ex) { | |
echo $ex; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"repositories": [{ | |
"type": "vcs", | |
"url": "http://github.com/Hywan/websocket" | |
} | |
], | |
"name": "Julien/ws", | |
"require": { | |
"hoa/websocket": "dev-blocking" | |
}, | |
"minimum-stability": "dev" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
try { | |
$s = new Hoa\Socket\Server('tcp://127.0.0.1:8889'); | |
$server = new Hoa\Websocket\Server($s); | |
$server->on('open', function ( Hoa\Core\Event\Bucket $bucket ) { | |
echo 'Open'."\r\n"; | |
return; | |
}); | |
$server->on('message', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo $data['message']."\r\n"; | |
return; | |
}); | |
$server->on('close', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo 'Close : '.$data['code'].'('.$data['reason'].')'."\r\n"; | |
return; | |
}); | |
$server->on('error', function ( Hoa\Core\Event\Bucket $bucket ) { | |
$data = $bucket->getData(); | |
echo 'Error : '.$data['exception']."\r\n"; | |
return; | |
}); | |
$server->run(); | |
} | |
catch(Exception $ex) { | |
echo $ex; | |
} | |
?> |
et le tout sur windows 7 64bits
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ php client.php
Hoa\Websocket\Client::doHandshake(): (0) Handshake has failed, the server did not return a valid response.
Client:
GET / HTTP/1.1
Host: 127.0.0.1
User-Agent: Hoa
Upgrade: WebSocket
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: NjM3ODQ2OTktNGYxNy00Mg==
Sec-WebSocket-Version: 13
Server:
HTTP/1.1 101 Switching Protocols
in C:\www\nox\Site\vendor\hoa\websocket\Hoa\Websocket\Client.php at line 201.
&&
$ php server.php
Open
Close : 1000()
Avec biensur le serveur lancé avant le client 🌴