(Request-Line) GET / HTTP/1.1
Host localhost:9999
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-US,en;q=0.5
Accept-Encoding gzip, deflate
Sec-WebSocket-Version 13
Origin http://localhost:8080
Sec-WebSocket-Key qFgapj5i/4X84InTFx1/KQ==
Connection keep-alive, Upgrade
Pragma no-cache
Cache-Control no-cache
Upgrade websocket
(Status-Line) HTTP/1.1 400 Bad Request
X-Powered-By Ratchet/0.3.2
Provisional headers are shown
Cache-Control: no-cache
Connection:Upgrade
Host: localhost:9999
Origin: http://localhost:8080
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
Sec-WebSocket-Key: dkUN6SpXshMhANfKnEXrxg==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
Error during WebSocket handshake: Unexpected response code: 400
public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0',$loop=false) {
if($loop===false){
$loop = LoopFactory::create();
}
//rest of normal code
}
<?php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
//use MyApp\WebApp;
require ('./vendor/autoload.php');
$Config=array();
//http
$Config['HttpInterface' ]= '0.0.0.0';
$Config['HttpPort' ]= 8080;
//web socket
$Config['WebsocketInterface']= '0.0.0.0';
$Config['WebsocketPort' ]= 9999;
//raw socket
$Config['SocketInterface' ]= '0.0.0.0';
$Config['SocketPort' ]= 8888;
//loop
$loop = React\EventLoop\Factory::create();
class Chat implements Ratchet\MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(Ratchet\ConnectionInterface $conn) {
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(Ratchet\ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send($msg);
}
}
}
public function onClose(Ratchet\ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected\n";
}
public function onError(Ratchet\ConnectionInterface $conn, \Exception $e) {
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
$HttpApp = function ($request, $response) use ($Config){
$response->writeHead(200,array('Content-Type'=>'text/html'));
$response->end(
"<script type=\"text/javascript\">
console.log('starting...');
setTimeout(function(){
console.log('starting connection...');
var conn = new WebSocket('ws://localhost:".$Config['WebsocketPort']."');
conn.onopen = function(e) {
console.log(\"Connection established!\");
};
conn.onopen = function(e){
console.log(e);
}
conn.onmessage = function(e) {
console.log(e.data);
};
conn.onerror = function(err){
console.log(err);
}
},1000);
</script>
"
);
};
//Servers
$Servers=array();
//Server: WebSocket
$Servers['WebSocket']=array();
$Servers['WebSocket']['Server']=IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
)
,$Config['WebsocketPort']
,$Config['WebsocketInterface']
,$loop
);
//Server: TCP Socket
$Servers['TCP']=array();
$Servers['TCP']['Server'] = IoServer::factory(
new Chat()
,$Config['SocketPort']
,$Config['SocketInterface']
,$loop
);
//Server: Http
$Servers['HTTP']=array();
$Servers['HTTP']['Socket'] = new React\Socket\Server($loop);
$Servers['HTTP']['Http'] = new React\Http\Server($Servers['HTTP']['Socket'], $loop);
$Servers['HTTP']['Http'] ->on('request', $HttpApp);
$Servers['HTTP']['Socket'] ->listen($Config['HttpPort']);
$loop->run();
<?php
use Ratchet\Server\IoServer;
require './vendor/autoload.php';
class Chat implements Ratchet\MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(Ratchet\ConnectionInterface $conn) {
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(Ratchet\ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send($msg);
}
}
}
public function onClose(Ratchet\ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected\n";
}
public function onError(Ratchet\ConnectionInterface $conn, \Exception $e) {
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
$server = IoServer::factory(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Chat()
)
),
8080
);
$server->run();
...
public function onError(Ratchet\ConnectionInterface $conn,<span style="colo
I will try to debug this.
Did you know these work on open wrt?
--
---
You received this message because you are subscribed to a topic in the Google Groups "Ratchet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ratchet-php/IjFBcsWJa8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ratchet-php...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to ratchet-php+unsubscribe@googlegroups.com.
I'm building a open wrt mesh with mr3020s for home automation and control everything with a distributed php framework. Switching from nodes got me from 20 MB ram to 3 so I have a lot more room to work with. If you're interested I could post the code when the prototype is ready....
To unsubscribe from this group and all its topics, send an email to ratchet-php...@googlegroups.com.
public function verifyKey($val) {
var_dump($val); // string(24) "zyaDPNPpaGmi8BM5VUzTaQ=="
var_dump(base64_decode((string)$val)); // string(16) "╧&â<╙Θhió≡‼9UL╙i"
var_dump(strlen(base64_decode((string)$val))); // int(10)
return (16 === strlen(base64_decode((string)$val)));
}
php --version
PHP 5.5.15 (cli) (built: Jul 23 2014 15:05:09)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
To unsubscribe from this group and all its topics, send an email to ratchet-php...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Ratchet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ratchet-php/IjFBcsWJa8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ratchet-php...@googlegroups.com.
public function verifyKey($val) {
return (16 === strlen(base64_decode((string)$val)) || ( (int)ini_get('mbstring.func_overload') & 2 && 16 === mb_strlen(utf8_encode(base64_decode((string)$val)))));
}
...