Make a WebSocket example work with crawler.yt.lemnoslife.com
This commit is contained in:
parent
411a3db465
commit
1fe92ec2d0
@ -13,8 +13,7 @@ See <?php echoUrl('https://gitea.lemnoslife.com/Benjamin_Loison/YouTube_captions
|
||||
<button>Search</button>
|
||||
|
||||
<script>
|
||||
// Then some JavaScript in the browser:
|
||||
var conn = new WebSocket('ws://localhost:8080/echo');
|
||||
var conn = new WebSocket('wss://crawler.yt.lemnoslife.com:443/websocket');
|
||||
conn.onmessage = function(e) { console.log(e.data); };
|
||||
conn.onopen = function(e) { conn.send('Hello Me!'); };
|
||||
</script>
|
||||
|
@ -7,8 +7,7 @@ use Ratchet\ConnectionInterface;
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* chat.php
|
||||
* Send any incoming messages to all connected clients (except sender)
|
||||
* Send any incoming messages to all connected clients
|
||||
*/
|
||||
class MyChat implements MessageComponentInterface
|
||||
{
|
||||
@ -26,11 +25,7 @@ class MyChat implements MessageComponentInterface
|
||||
|
||||
public function onMessage(ConnectionInterface $from, $msg)
|
||||
{
|
||||
foreach ($this->clients as $client) {
|
||||
if ($from != $client) {
|
||||
$client->send($msg);
|
||||
}
|
||||
}
|
||||
$from->send($msg);
|
||||
}
|
||||
|
||||
public function onClose(ConnectionInterface $conn)
|
||||
@ -44,8 +39,7 @@ class MyChat implements MessageComponentInterface
|
||||
}
|
||||
}
|
||||
|
||||
// Run the server application through the WebSocket protocol on port 8080
|
||||
$app = new Ratchet\App('localhost', 8080);
|
||||
$app->route('/chat', new MyChat(), array('*'));
|
||||
$app->route('/echo', new Ratchet\Server\EchoServer(), array('*'));
|
||||
// Run the server application through the WebSocket protocol on port 4430
|
||||
$app = new Ratchet\App('crawler.yt.lemnoslife.com', 4430);
|
||||
$app->route('/websocket', new MyChat(), array('*'));
|
||||
$app->run();
|
||||
|
Loading…
Reference in New Issue
Block a user