Exemplo n.º 1
0
 /**
  * Send a message to WebSocket clients (use port + 1 for SSL connections)
  */
 public static function send($type, $msg, $to = false)
 {
     $proto = self::$ssl ? 'wss' : 'ws';
     $port = self::$ssl ? self::$port + 1 : self::$port;
     $ws = new WebSocketClient("{$proto}://localhost:" . self::$port);
     $ws->send(json_encode(array('type' => $type, 'from' => self::$clientID, 'msg' => $msg, 'to' => $to)));
     $ws->close();
 }
Exemplo n.º 2
0
<?php

require __DIR__ . '/WebSocketClient.class.php';
// Connect to the WebSocket server
$ws = new WebSocketClient('ws://localhost:1729');
// Send some messages
$ws->send('Foo');
$ws->send('Bar');
$ws->send('Baz');
// Close the connection
$ws->close();
// Now do the same for SSL
$ws = new WebSocketClient('wss://localhost:1730');
$ws->send('Foo');
$ws->send('Bar');
$ws->send('Baz');
$ws->close();