hoaproject / Websocket

The Hoa\Websocket library.
https://hoa-project.net/
422 stars 75 forks source link

how can i get url query string value? #103

Closed chaclee closed 6 years ago

chaclee commented 6 years ago

eg:ws://127.0.0.1:8000/?id=1&name=abcd

how to get name=abcd?

Hywan commented 6 years ago

Hello,

Sorry for the late reply.

The query strings are parsed correctly and appended to the path here (line 121):

https://github.com/hoaproject/Websocket/blob/a2a5964ed4daf971d4780476359d39be3d4ce046/Socket.php#L117-L122

which is passed to the $endpoint here:

https://github.com/hoaproject/Websocket/blob/a2a5964ed4daf971d4780476359d39be3d4ce046/Socket.php#L67

So you can read it with getEndpoint:

https://github.com/hoaproject/Websocket/blob/a2a5964ed4daf971d4780476359d39be3d4ce046/Socket.php#L82-L86

So basically, within a Hoa\Websocket\Server instance, you can read it by writing:

$server->getConnection()->getSocket()->getEndpoint()

Thoughts?

Hywan commented 6 years ago

However, I suppose it won't work. I'm not sure the server strips off the query strings from the client.

What are you trying to achieve :-)?