reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.
https://reactphp.org/socket/
MIT License
1.2k stars 156 forks source link

No support for websockets? #227

Closed Henshall closed 4 years ago

Henshall commented 4 years ago

Hello - I have been trying to get web sockets working with this for the last few days - specifically url's such as "wss://cerberus-xxxx.lb.slack-msgs.com/websocket/KHAM3gifDwkNzSW1epUuKursfVk...". Is this type of url supported? It seems that it does not work but also does not return any errors.

I have the following code:

$loop = Factory::create(); $connector = new Connector($loop); $connector->connect($url)->then(function (ConnectionInterface $connection) use ($loop) { $connection->pipe(new WritableResourceStream(STDOUT, $loop)); $connection->write('{ "type": "message", "ts": "11111", "user": "noone", "text": "sample text" }'); }); $loop->run();

Thank you!

HLeithner commented 4 years ago

Reactphp Sockets are RAW Socket connections, Websockets is a protocol which needs an implementation like Ratchet or Thruway.

There is a blog post by @WyriHaximus about this topic https://blog.wyrihaximus.net/2015/03/reactphp-sockets/

ghost commented 4 years ago

As mentioned, react/socket implements raw sockets while WebSockets is a network protocol on top of TCP/IP sockets and uses HTTP as initial handshake. You should check out Pawl and WebSocketMiddleware for websocket client and server respectively. Or Ratchet for a higher level websocket server.

They all build on top of ReactPHP to implement websockets.

clue commented 4 years ago

I'll assume this is resolved and will close this for now, please feel free to report back otherwise :+1: