I'm trying to establish a websocket connection with the push Notification server from the examples
var conn = new WebSocket('ws://10.0.0.23:8080');
but the connection is not upgraded to websocket.
request header:
GET ws://10.0.0.23:8080/ HTTP/1.1
Host: 10.0.0.23:8080
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://xxx
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: de,en-US;q=0.9,en;q=0.8
Sec-WebSocket-Key: CbYPFT8CVPy18w6mtYGQNw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
response header
Connection:Upgrade
Sec-WebSocket-Protocol:0
Sec-WebSocket-Version:13
Upgrade:websocket
X-Powered-By:Ratchet/0.4.1
Can you provide some your server code? The response is very strange...half of the response looks like a success response and half looks like a failure response. As well, it's indicating support for HyBi which was completely removed in 0.4. Can you add the first line of the HTTP response as well; which status code was returned?
Server Code:
$loop = React\EventLoop\Factory::create();
$pusher = new Pusher;
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
And the full response header
HTTP/1.1 426 No Sec-WebSocket-Protocols requested supported
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: 0
X-Powered-By: Ratchet/0.4.1
What is the result of the command composer show -i in your repository?
Hi,
I have the same problem.
Request headers:
GET wss://ws.domain.tld/ HTTP/1.1
Host: ws.domain.tld
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: https://ws.domain.tld
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept-Encoding: gzip, deflate, br
Accept-Language: cs,sk;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: _ga=GA1.2.1303556860.1502960822
Sec-WebSocket-Key: lQnrE833blQIci8s17NZjQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: wamp.2.json, wamp.2.msgpack
Response headers:
HTTP/1.1 426 No Sec-WebSocket-Protocols requested supported
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: 0
X-Powered-By: Ratchet/0.4.1
Result of composer show -i
cboden/ratchet v0.4.1 PHP WebSocket library
evenement/evenement v2.1.0 脡v茅nement is a very simple event dispatching library for PHP
guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides common utility methods
predis/predis v1.1.1 Flexible and feature-complete Redis client for PHP and HHVM
psr/http-message 1.0.1 Common interface for HTTP messages
ratchet/rfc6455 v0.2.3 RFC6455 WebSocket protocol handler
react/cache v0.4.2 Async, Promise-based cache interface for ReactPHP
react/dns v0.4.12 Async DNS resolver for ReactPHP
react/event-loop v0.4.3 Event loop abstraction layer that libraries can use for evented I/O.
react/promise v2.5.1 A lightweight implementation of CommonJS Promises/A for PHP
react/promise-timer v1.2.1 A trivial implementation of timeouts for Promises, built on top of ReactPHP.
react/socket v0.8.9 Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP
react/stream v0.7.7 Event-driven readable and writable streams for non-blocking I/O in ReactPHP
react/zmq v0.3.0 ZeroMQ bindings for React.
symfony/http-foundation v4.0.4 Symfony HttpFoundation Component
symfony/polyfill-mbstring v1.7.0 Symfony polyfill for the Mbstring extension
symfony/routing v4.0.4 Symfony Routing Component
I might add, that the Chat demo works without any issues. Its the push demo server that doesn't work.
I also tried to connect to it using ThruwayPHP which connects locally (ignoring my apache proxy) and I get the same result.
@Erseni The example is a WAMP server which is a protocol that is built on top of websockets.
In order to speak WAMP, your request would need to specific wamp in the Sec-WebSocket-Protocol header. (or use a WAMP library)
If you just want to do plain websockets, you could create a pusher class that implements the MessageComponentInterface and then leave WampServer out of the stack.
Most helpful comment
@Erseni The example is a WAMP server which is a protocol that is built on top of websockets.
In order to speak WAMP, your request would need to specific
wampin theSec-WebSocket-Protocolheader. (or use a WAMP library)If you just want to do plain websockets, you could create a pusher class that implements the
MessageComponentInterfaceand then leaveWampServerout of the stack.