amphp / websocket-client

Async WebSocket client for PHP based on Amp.
https://amphp.org/websocket-client
MIT License
148 stars 18 forks source link

Specify timeout #25

Closed juzi5201314 closed 4 years ago

juzi5201314 commented 4 years ago

Allow specified connection timeout? Now when the target cannot be accessed, "Uncaught Amp \ Socket \ ConnectException: Connecting to tcp: // localhost: 10000 failed: timeout exceeded (10000 ms)" will occur. But the 10 second timeout is too long

trowski commented 4 years ago

The easiest way is to use a TimeoutCancellationToken passed to Connector::connect() to reduce the overall connection timeout.

You can also use the HttpClient passed to Rfc6455Connector to modify the request timeouts. However this is a bit clunky for something that should be simpler. In that light, I've added some methods to Handshake (in ab84d50d131222c057050dac3b3cb800761c4352) to easily modify the TCP connect timeout and TLS handshake timeout (if applicable).